Skip to content

Commit 1cfedac

Browse files
Fix flaky tests (#18835)
Signed-off-by: Arthur Schreiber <[email protected]>
1 parent 885917d commit 1cfedac

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

go/vt/topo/consultopo/server_flaky_test.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ func startConsul(t *testing.T, authToken string) (*exec.Cmd, string, string) {
128128
}
129129

130130
func TestConsulTopo(t *testing.T) {
131+
originalWatchPollDuration := watchPollDuration
132+
defer func() {
133+
watchPollDuration = originalWatchPollDuration
134+
}()
135+
131136
// One test is going to wait that full period, so make it shorter.
132137
watchPollDuration = 100 * time.Millisecond
133138

@@ -150,6 +155,7 @@ func TestConsulTopo(t *testing.T) {
150155
testIndex := 0
151156
ctx, cancel := context.WithCancel(context.Background())
152157
defer cancel()
158+
153159
test.TopoServerTestSuite(t, ctx, func() *topo.Server {
154160
// Each test will use its own sub-directories.
155161
testRoot := fmt.Sprintf("test-%v", testIndex)
@@ -175,6 +181,16 @@ func TestConsulTopo(t *testing.T) {
175181

176182
func TestConsulTopoWithChecks(t *testing.T) {
177183
// One test is going to wait that full period, so make it shorter.
184+
originalWatchPollDuration := watchPollDuration
185+
originalConsulLockSessionChecks := consulLockSessionChecks
186+
originalConsulLockSessionTTL := consulLockSessionTTL
187+
188+
defer func() {
189+
watchPollDuration = originalWatchPollDuration
190+
consulLockSessionTTL = originalConsulLockSessionTTL
191+
consulLockSessionChecks = originalConsulLockSessionChecks
192+
}()
193+
178194
watchPollDuration = 100 * time.Millisecond
179195
consulLockSessionChecks = "serfHealth"
180196
consulLockSessionTTL = "15s"
@@ -248,6 +264,11 @@ func TestConsulTopoWithAuth(t *testing.T) {
248264
}
249265
defer os.Remove(tmpFile.Name())
250266

267+
originalConsulAuthClientStaticFile := consulAuthClientStaticFile
268+
defer func() {
269+
consulAuthClientStaticFile = originalConsulAuthClientStaticFile
270+
}()
271+
251272
consulAuthClientStaticFile = tmpFile.Name()
252273

253274
jsonConfig := "{\"global\":{\"acl_token\":\"123456\"}, \"test\":{\"acl_token\":\"123456\"}}"
@@ -299,6 +320,11 @@ func TestConsulTopoWithAuthFailure(t *testing.T) {
299320
}
300321
defer os.Remove(tmpFile.Name())
301322

323+
originalConsulAuthClientStaticFile := consulAuthClientStaticFile
324+
defer func() {
325+
consulAuthClientStaticFile = originalConsulAuthClientStaticFile
326+
}()
327+
302328
consulAuthClientStaticFile = tmpFile.Name()
303329

304330
// check valid, empty json causes error
@@ -346,10 +372,10 @@ func TestConsulTopoWithAuthFailure(t *testing.T) {
346372
func TestConsulWatcherStormPrevention(t *testing.T) {
347373
// Save original values and restore them after the test
348374
originalWatchPollDuration := watchPollDuration
349-
originalAuthFile := consulAuthClientStaticFile
375+
originalConsulAuthClientStaticFile := consulAuthClientStaticFile
350376
defer func() {
351377
watchPollDuration = originalWatchPollDuration
352-
consulAuthClientStaticFile = originalAuthFile
378+
consulAuthClientStaticFile = originalConsulAuthClientStaticFile
353379
}()
354380

355381
// Configure test settings - using direct assignment since flag parsing in tests is complex
@@ -368,7 +394,9 @@ func TestConsulWatcherStormPrevention(t *testing.T) {
368394
os.Remove(configFilename)
369395
}()
370396

371-
ctx := context.Background()
397+
ctx, cancel := context.WithCancel(context.Background())
398+
defer cancel()
399+
372400
testRoot := "storm-test"
373401

374402
// Create the topo server

go/vt/vtadmin/vtctldclient/proxy_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ func TestDialSecureDialOptionError(t *testing.T) {
272272
// Parse the flags which will set the cert and key variables in grpcclientcommon
273273
err = fs.Parse(os.Args[1:])
274274
require.NoError(t, err)
275+
// reset flags after test
276+
defer func() {
277+
_ = fs.Parse([]string{
278+
"vtadmin",
279+
"--vtctld-grpc-cert=",
280+
"--vtctld-grpc-key=",
281+
})
282+
}()
275283

276284
// Now when we create a proxy, it should fail at line 116
277285
disco := fakediscovery.New()

0 commit comments

Comments
 (0)