Skip to content

Commit e882d97

Browse files
author
Kazuyoshi Kato
authored
test: use EventuallyWithT methods correctly (#4583)
The inner function should use assert.CollectT to keep the loop running.
1 parent 383da94 commit e882d97

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

test/preflight/fly_postgres_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ func assertMachineCount(tb assert.TestingT, f *testlib.FlyctlTestEnv, appName st
167167

168168
// assertPostgresIsUp checks that the given Postgres server is really up.
169169
// Even after "fly pg create", sometimes the server is not ready for accepting connections.
170-
func assertPostgresIsUp(tb testing.TB, f *testlib.FlyctlTestEnv, appName string) {
171-
tb.Helper()
172-
170+
func assertPostgresIsUp(tb assert.TestingT, f *testlib.FlyctlTestEnv, appName string) {
173171
ssh := f.FlyAllowExitFailure(`ssh console -a %s -u postgres -C "psql -p 5433 -h /run/postgresql -c 'SELECT 1'"`, appName)
174172
assert.Equal(tb, 0, ssh.ExitCode(), "failed to connect to postgres at %s: %s", appName, ssh.StdErr())
175173
}
@@ -196,7 +194,7 @@ func TestPostgres_ImportSuccess(t *testing.T) {
196194
"pg create --org %s --name %s --region %s --initial-cluster-size 1 --vm-size %s --volume-size 1",
197195
f.OrgSlug(), secondAppName, f.PrimaryRegion(), postgresMachineSize,
198196
)
199-
assert.EventuallyWithT(t, func(c *assert.CollectT) {
197+
assert.EventuallyWithT(t, func(t *assert.CollectT) {
200198
assertPostgresIsUp(t, f, firstAppName)
201199
}, 1*time.Minute, 10*time.Second)
202200

@@ -222,7 +220,7 @@ func TestPostgres_ImportSuccess(t *testing.T) {
222220
require.Contains(f, output, firstAppName)
223221

224222
// Wait for the importer machine to be destroyed.
225-
assert.EventuallyWithT(t, func(c *assert.CollectT) {
223+
assert.EventuallyWithT(t, func(t *assert.CollectT) {
226224
assertMachineCount(t, f, secondAppName, 1)
227225
}, 2*time.Minute, 10*time.Second, "import machine not destroyed")
228226
}
@@ -244,7 +242,7 @@ func TestPostgres_ImportFailure(t *testing.T) {
244242
"pg create --org %s --name %s --region %s --initial-cluster-size 1 --vm-size %s --volume-size 1 --password x",
245243
f.OrgSlug(), appName, f.PrimaryRegion(), postgresMachineSize,
246244
)
247-
assert.EventuallyWithT(t, func(c *assert.CollectT) {
245+
assert.EventuallyWithT(t, func(t *assert.CollectT) {
248246
assertPostgresIsUp(t, f, appName)
249247
}, 1*time.Minute, 10*time.Second)
250248

@@ -256,7 +254,7 @@ func TestPostgres_ImportFailure(t *testing.T) {
256254
require.Contains(f, result.StdOut().String(), "database \"test\" does not exist")
257255

258256
// Wait for the importer machine to be destroyed.
259-
assert.EventuallyWithT(t, func(c *assert.CollectT) {
257+
assert.EventuallyWithT(t, func(t *assert.CollectT) {
260258
assertMachineCount(t, f, appName, 1)
261259
}, 1*time.Minute, 10*time.Second, "import machine not destroyed")
262260
}

test/preflight/fly_volume_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,29 @@ func testVolumeLs(t *testing.T) {
9797
f.Fly("vol destroy -y %s", destroyed.ID)
9898

9999
// Deleted volumes shouldn't be shown.
100-
assert.EventuallyWithT(f, func(c *assert.CollectT) {
100+
assert.EventuallyWithT(f, func(t *assert.CollectT) {
101101
lsRes := f.Fly("vol ls -a %s --json", appName)
102102
var ls []*fly.Volume
103103
lsRes.StdOutJSON(&ls)
104-
assert.Lenf(f, ls, 1, "volume %s is still visible", destroyed.ID)
105-
assert.Equal(f, kept.ID, ls[0].ID)
104+
assert.Lenf(t, ls, 1, "volume %s is still visible", destroyed.ID)
105+
assert.Equal(t, kept.ID, ls[0].ID)
106106
}, 5*time.Minute, 10*time.Second)
107107

108108
// Deleted volumes should be shown with --all.
109-
assert.EventuallyWithT(f, func(c *assert.CollectT) {
109+
assert.EventuallyWithT(f, func(t *assert.CollectT) {
110110
lsAllRes := f.Fly("vol ls --all -a %s --json", appName)
111111

112112
var lsAll []*fly.Volume
113113
lsAllRes.StdOutJSON(&lsAll)
114114

115-
assert.Len(f, lsAll, 2)
115+
assert.Len(t, lsAll, 2)
116116

117117
var lsAllIds []string
118118
for _, v := range lsAll {
119119
lsAllIds = append(lsAllIds, v.ID)
120120
}
121-
assert.Contains(f, lsAllIds, kept.ID)
122-
assert.Contains(f, lsAllIds, destroyed.ID)
121+
assert.Contains(t, lsAllIds, kept.ID)
122+
assert.Contains(t, lsAllIds, destroyed.ID)
123123
}, 5*time.Minute, 10*time.Second)
124124
}
125125

0 commit comments

Comments
 (0)