Skip to content

Commit 353f0ca

Browse files
committed
test: fix asserting etcd members test
In test `AssertEtcdMembershipMatchesOmniResources` we compare existing etcd members with ClusterMachines with retry, however we weren't refreshing etcd member list after the first fetch and this lead to test failure if the member list info was constructed incorrectly. Signed-off-by: Oguz Kilcan <[email protected]>
1 parent f42a94a commit 353f0ca

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

internal/integration/talos_test.go

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -285,24 +285,21 @@ func AssertTalosAPIAccessViaOmni(testCtx context.Context, omniClient *client.Cli
285285
// AssertEtcdMembershipMatchesOmniResources checks that etcd members are in sync with the Omni MachineStatus information.
286286
func AssertEtcdMembershipMatchesOmniResources(testCtx context.Context, client *client.Client, cluster string) TestFunc {
287287
return func(t *testing.T) {
288-
require := require.New(t)
289-
assert := assert.New(t)
290-
291-
ctx, cancel := context.WithTimeout(testCtx, 90*time.Second)
288+
ctx, cancel := context.WithTimeout(testCtx, 5*time.Minute)
292289
defer cancel()
293290

294291
data, err := client.Management().Talosconfig(ctx)
295-
require.NoError(err)
296-
assert.NotEmpty(data)
292+
require.NoError(t, err)
293+
assert.NotEmpty(t, data)
297294

298295
config, err := clientconfig.FromBytes(data)
299-
require.NoError(err)
296+
require.NoError(t, err)
300297

301298
c, err := talosclient.New(ctx, talosclient.WithConfig(config), talosclient.WithCluster(cluster))
302-
require.NoError(err)
299+
require.NoError(t, err)
303300

304301
t.Cleanup(func() {
305-
require.NoError(c.Close())
302+
require.NoError(t, c.Close())
306303
})
307304

308305
machineIDs := rtestutils.ResourceIDs[*omni.ClusterMachine](ctx, t, client.Omni().State(),
@@ -314,43 +311,41 @@ func AssertEtcdMembershipMatchesOmniResources(testCtx context.Context, client *c
314311

315312
clearConnectionRefused(ctx, t, c, len(machineIDs), machineIDs...)
316313

317-
resp, err := c.EtcdMemberList(ctx, &machine.EtcdMemberListRequest{})
318-
require.NoError(err)
314+
require.EventuallyWithT(t, func(collect *assert.CollectT) {
315+
require.NoError(t, ctx.Err())
316+
317+
resp, err := c.EtcdMemberList(ctx, &machine.EtcdMemberListRequest{})
318+
require.NoError(collect, err)
319319

320-
err = retry.Constant(time.Minute*2, retry.WithUnits(time.Second)).Retry(func() error {
321320
clusterMachines := map[string]any{}
322321

323322
for _, machineID := range machineIDs {
324323
var machineStatus *omni.MachineStatus
325324

326325
machineStatus, err = safe.StateGet[*omni.MachineStatus](ctx, client.Omni().State(), omni.NewMachineStatus(resources.DefaultNamespace, machineID).Metadata())
327-
if err != nil {
328-
return retry.ExpectedError(err)
329-
}
326+
require.NoError(collect, err)
330327

331328
clusterMachines[machineStatus.TypedSpec().Value.Network.Hostname] = struct{}{}
332329
}
333330

334331
for _, m := range resp.Messages {
335-
if len(clusterMachines) != len(m.Members) {
332+
if !assert.True(collect, len(clusterMachines) == len(m.Members)) {
336333
memberIDs := xslices.Map(m.Members, func(m *machine.EtcdMember) string { return etcd.FormatMemberID(m.Id) })
337334

338-
return retry.ExpectedErrorf("the count of members doesn't match the count of machines, expected %d, got: %d, members list: %s", len(clusterMachines), len(m.Members), memberIDs)
335+
t.Logf("the count of members doesn't match the count of machines, expected %d, got: %d, members list: %s", len(clusterMachines), len(m.Members), memberIDs)
336+
return
339337
}
340338

341339
for _, member := range m.Members {
342340
_, ok := clusterMachines[member.Hostname]
343341

344-
if !ok {
345-
return retry.ExpectedErrorf("found etcd member which doesn't have associated machine status")
342+
if !assert.True(collect, ok) {
343+
t.Logf("found etcd member which doesn't have associated machine status")
344+
return
346345
}
347346
}
348347
}
349-
350-
return nil
351-
})
352-
353-
require.NoError(err)
348+
}, 5*time.Minute, 20*time.Second)
354349
}
355350
}
356351

0 commit comments

Comments
 (0)