De-flake TestJetStreamClusterAccountPurge by waiting for account to exist

Signed-off-by: Neil Twigg <neil@nats.io>
This commit is contained in:
Neil Twigg
2023-09-14 11:40:30 +01:00
parent ea93e77b7f
commit 904f4c388e
2 changed files with 21 additions and 0 deletions

View File

@@ -3738,6 +3738,8 @@ func TestJetStreamClusterAccountPurge(t *testing.T) {
updateJwt(t, c.randomServer().ClientURL(), sysCreds, sysJwt, 3)
updateJwt(t, c.randomServer().ClientURL(), sysCreds, accJwt, 3)
c.waitOnAccount(accpub)
createTestData := func(t *testing.T) {
nc, js := jsClientConnect(t, c.randomNonLeader(), nats.UserCredentials(accCreds))
defer nc.Close()

View File

@@ -1435,6 +1435,25 @@ func (c *cluster) waitOnLeader() {
c.t.Fatalf("Expected a cluster leader, got none")
}
func (c *cluster) waitOnAccount(account string) {
c.t.Helper()
expires := time.Now().Add(40 * time.Second)
for time.Now().Before(expires) {
found := true
for _, s := range c.servers {
acc, err := s.fetchAccount(account)
found = found && err == nil && acc != nil
}
if found {
return
}
time.Sleep(100 * time.Millisecond)
continue
}
c.t.Fatalf("Expected account %q to exist but didn't", account)
}
// Helper function to check that a cluster is formed
func (c *cluster) waitOnClusterReady() {
c.t.Helper()