Skip to content

Commit

Permalink
test: improve flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rueian committed Jul 13, 2023
1 parent b10717d commit 7ecc0de
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,33 @@ services:
- "7004:7004"
- "7005:7005"
- "7006:7006"
cluster5adapter:
image: redis:5-alpine
entrypoint:
- /bin/sh
- -c
- |
redis-server --port 7007 --save "" --appendonly no --cluster-enabled yes --cluster-config-file 7007.conf &
redis-server --port 7008 --save "" --appendonly no --cluster-enabled yes --cluster-config-file 7008.conf &
redis-server --port 7009 --save "" --appendonly no --cluster-enabled yes --cluster-config-file 7009.conf &
while ! redis-cli --cluster create 127.0.0.1:7007 127.0.0.1:7008 127.0.0.1:7009 --cluster-yes; do sleep 1; done
wait
ports:
- "7007:7007"
- "7008:7008"
- "7009:7009"
clusteradapter:
image: redis:7.2-rc-alpine
entrypoint:
- /bin/sh
- -c
- |
redis-server --port 7010 --save "" --appendonly no --cluster-enabled yes --cluster-config-file 7010.conf &
redis-server --port 7011 --save "" --appendonly no --cluster-enabled yes --cluster-config-file 7011.conf &
redis-server --port 7012 --save "" --appendonly no --cluster-enabled yes --cluster-config-file 7012.conf &
while ! redis-cli --cluster create 127.0.0.1:7010 127.0.0.1:7011 127.0.0.1:7012 --cluster-yes; do sleep 1; done
wait
ports:
- "7010:7010"
- "7011:7011"
- "7012:7012"
11 changes: 7 additions & 4 deletions internal/util/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ func TestPool(t *testing.T) {
}
c.s[0] = 1
p.Put(c)
c = p.Get(5, 10)
if c.s[0] != 1 {
t.Fatal("should use recycled")
for {
c = p.Get(5, 10)
if c.s[0] == 1 {
break
}
c.s[0] = 1
p.Put(c)
}
p.Put(c)
c = p.Get(5, 20)
if c.s[0] != 0 {
t.Fatal("should not use recycled")
Expand Down
6 changes: 3 additions & 3 deletions rueidiscompat/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var _ = BeforeSuite(func() {
})
Expect(err).NotTo(HaveOccurred())
clusterresp3, err = rueidis.NewClient(rueidis.ClientOption{
InitAddress: []string{"127.0.0.1:7001"},
InitAddress: []string{"127.0.0.1:7010"},
ClientName: "rueidis",
})
Expect(err).NotTo(HaveOccurred())
Expand All @@ -78,7 +78,7 @@ var _ = BeforeSuite(func() {
})
Expect(err).NotTo(HaveOccurred())
clusterresp2, err = rueidis.NewClient(rueidis.ClientOption{
InitAddress: []string{"127.0.0.1:7004"},
InitAddress: []string{"127.0.0.1:7007"},
ClientName: "rueidis",
DisableCache: true,
})
Expand Down Expand Up @@ -8545,7 +8545,7 @@ func testAdapterCache(resp3 bool) {
for _, test := range convTests {
err := adapter.Set(ctx, "key", test.value, 0).Err()
Expect(err).NotTo(HaveOccurred())

time.Sleep(time.Millisecond * 10)
s, err := adapter.Cache(time.Hour).Get(ctx, "key").Result()
Expect(err).NotTo(HaveOccurred())
Expect(s).To(Equal(test.wanted))
Expand Down

0 comments on commit 7ecc0de

Please sign in to comment.