Skip to content

Commit acbf953

Browse files
committed
test: small test optimizations
1 parent 126d87f commit acbf953

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

redis/redis_test.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ var _ = Describe("Redis client", func() {
151151
Eventually(func() map[string]int {
152152
return redisServer.PubSubNumSub(SyncChannelName)
153153
}).Should(HaveLen(1))
154-
}, SpecTimeout(time.Second*6))
154+
}, SpecTimeout(time.Second*3))
155155
})
156156
})
157157

@@ -225,7 +225,7 @@ var _ = Describe("Redis client", func() {
225225
Eventually(func() chan *CacheMessage {
226226
return redisClient.CacheChannel
227227
}).Should(HaveLen(lenE + 1))
228-
}, SpecTimeout(time.Second*6))
228+
}, SpecTimeout(time.Second*3))
229229
})
230230
When("wrong data is received", func() {
231231
It("should not propagate the message over the channel if data is wrong", func(ctx context.Context) {
@@ -258,7 +258,7 @@ var _ = Describe("Redis client", func() {
258258
Eventually(func() chan *CacheMessage {
259259
return redisClient.CacheChannel
260260
}).Should(HaveLen(lenC))
261-
}, SpecTimeout(time.Second*6))
261+
}, SpecTimeout(time.Second*3))
262262
It("should not propagate the message over the channel if type is wrong", func(ctx context.Context) {
263263
redisClient, err = New(ctx, redisConfig)
264264
Expect(err).Should(Succeed())
@@ -282,16 +282,15 @@ var _ = Describe("Redis client", func() {
282282
rec := redisServer.Publish(SyncChannelName, string(binMsg))
283283
Expect(rec).Should(Equal(1))
284284

285-
time.Sleep(2 * time.Second)
285+
// Use Consistently to verify channels don't receive invalid messages
286+
Consistently(func() int {
287+
return len(redisClient.EnabledChannel)
288+
}, "200ms", "50ms").Should(Equal(lenE))
286289

287-
Eventually(func() chan *EnabledMessage {
288-
return redisClient.EnabledChannel
289-
}).Should(HaveLen(lenE))
290-
291-
Eventually(func() chan *CacheMessage {
292-
return redisClient.CacheChannel
293-
}).Should(HaveLen(lenC))
294-
}, SpecTimeout(time.Second*6))
290+
Consistently(func() int {
291+
return len(redisClient.CacheChannel)
292+
}, "200ms", "50ms").Should(Equal(lenC))
293+
}, SpecTimeout(time.Second*3))
295294
})
296295
})
297296

resolver/query_logging_resolver_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type SlowMockWriter struct {
3131
func (m *SlowMockWriter) Write(entry *querylog.LogEntry) {
3232
m.entries = append(m.entries, entry)
3333

34-
time.Sleep(time.Second)
34+
time.Sleep(100 * time.Millisecond)
3535
}
3636

3737
func (m *SlowMockWriter) CleanUp() {
@@ -364,7 +364,7 @@ var _ = Describe("QueryLoggingResolver", func() {
364364
Expect(ierr).Should(Succeed())
365365

366366
return len(sut.logChan)
367-
}, "20s", "1µs").Should(Equal(cap(sut.logChan)))
367+
}, "3s", "1µs").Should(Equal(cap(sut.logChan)))
368368
})
369369
})
370370
})

server/server_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,8 @@ var _ = Describe("Running DNS server", func() {
697697
// start server
698698
go server.Start(ctx, errChan)
699699

700-
time.Sleep(100 * time.Millisecond)
700+
// Wait for server to start successfully (no errors)
701+
Consistently(errChan, "200ms").ShouldNot(Receive())
701702

702703
err = server.Stop(ctx)
703704

0 commit comments

Comments
 (0)