Skip to content

Commit 3a82923

Browse files
Fix test TestOfferUpdatedVersion (#279)
The test sometimes fails on my machine. The EventuallyExpect function needs a condition that returns false instead of failing when the expected message is not received, since a different message may be sent by the client. This fixes the test. I run it 100 times and it passes: `go test -run TestOfferUpdatedVersion/ws -v -race -count 100`
1 parent f299bc3 commit 3a82923

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

client/clientimpl_test.go

+23-20
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ func TestSetEffectiveConfig(t *testing.T) {
533533
t,
534534
func() bool {
535535
return rcvConfig.Load() != nil &&
536-
proto.Equal(sendConfig, rcvConfig.Load().(*protobufs.EffectiveConfig))
536+
proto.Equal(sendConfig, rcvConfig.Load().(*protobufs.EffectiveConfig))
537537
},
538538
)
539539

@@ -546,7 +546,7 @@ func TestSetEffectiveConfig(t *testing.T) {
546546
t,
547547
func() bool {
548548
return rcvConfig.Load() != nil &&
549-
proto.Equal(sendConfig, rcvConfig.Load().(*protobufs.EffectiveConfig))
549+
proto.Equal(sendConfig, rcvConfig.Load().(*protobufs.EffectiveConfig))
550550
},
551551
)
552552

@@ -765,18 +765,18 @@ func TestServerOfferConnectionSettings(t *testing.T) {
765765
},
766766

767767
OnOpampConnectionSettingsFunc: func(
768-
ctx context.Context, settings *protobufs.OpAMPConnectionSettings,
768+
ctx context.Context, settings *protobufs.OpAMPConnectionSettings,
769769
) error {
770770
assert.True(t, proto.Equal(opampSettings, settings))
771771
atomic.AddInt64(&gotOpampSettings, 1)
772772
return nil
773773
},
774774
},
775775
Capabilities: protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnTraces |
776-
protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnMetrics |
777-
protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnLogs |
778-
protobufs.AgentCapabilities_AgentCapabilities_AcceptsOtherConnectionSettings |
779-
protobufs.AgentCapabilities_AgentCapabilities_AcceptsOpAMPConnectionSettings,
776+
protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnMetrics |
777+
protobufs.AgentCapabilities_AgentCapabilities_ReportsOwnLogs |
778+
protobufs.AgentCapabilities_AgentCapabilities_AcceptsOtherConnectionSettings |
779+
protobufs.AgentCapabilities_AgentCapabilities_AcceptsOpAMPConnectionSettings,
780780
}
781781
settings.OpAMPServerURL = "ws://" + srv.Endpoint
782782
prepareClient(t, &settings, client)
@@ -823,7 +823,7 @@ func TestClientRequestConnectionSettings(t *testing.T) {
823823
settings := types.StartSettings{
824824
Callbacks: types.CallbacksStruct{
825825
OnOpampConnectionSettingsFunc: func(
826-
ctx context.Context, settings *protobufs.OpAMPConnectionSettings,
826+
ctx context.Context, settings *protobufs.OpAMPConnectionSettings,
827827
) error {
828828
assert.True(t, proto.Equal(opampSettings, settings))
829829
atomic.AddInt64(&clientGotOpampSettings, 1)
@@ -929,7 +929,7 @@ func TestReportAgentHealth(t *testing.T) {
929929
settings := types.StartSettings{
930930
OpAMPServerURL: "ws://" + srv.Endpoint,
931931
Capabilities: protobufs.AgentCapabilities_AgentCapabilities_ReportsEffectiveConfig |
932-
protobufs.AgentCapabilities_AgentCapabilities_ReportsHealth,
932+
protobufs.AgentCapabilities_AgentCapabilities_ReportsHealth,
933933
}
934934
prepareClient(t, &settings, client)
935935

@@ -1090,7 +1090,7 @@ func verifyRemoteConfigUpdate(t *testing.T, successCase bool, expectStatus *prot
10901090
},
10911091
},
10921092
Capabilities: protobufs.AgentCapabilities_AgentCapabilities_AcceptsRemoteConfig |
1093-
protobufs.AgentCapabilities_AgentCapabilities_ReportsRemoteConfig,
1093+
protobufs.AgentCapabilities_AgentCapabilities_ReportsRemoteConfig,
10941094
}
10951095
prepareClient(t, &settings, client)
10961096

@@ -1208,12 +1208,15 @@ type packageTestCase struct {
12081208
const packageUpdateErrorMsg = "cannot update packages"
12091209

12101210
func assertPackageStatus(t *testing.T,
1211-
testCase packageTestCase,
1212-
msg *protobufs.AgentToServer) (*protobufs.ServerToAgent, bool) {
1211+
testCase packageTestCase,
1212+
msg *protobufs.AgentToServer) (*protobufs.ServerToAgent, bool) {
12131213
expectedStatusReceived := false
12141214

12151215
status := msg.PackageStatuses
1216-
require.NotNil(t, status)
1216+
if status == nil {
1217+
// PackageStatuses is not yet reported, keep waiting.
1218+
return nil, false
1219+
}
12171220
assert.EqualValues(t, testCase.expectedStatus.ServerProvidedAllPackagesHash, status.ServerProvidedAllPackagesHash)
12181221

12191222
if testCase.expectedError != "" {
@@ -1286,7 +1289,7 @@ func verifyUpdatePackages(t *testing.T, testCase packageTestCase) {
12861289
},
12871290
PackagesStateProvider: localPackageState,
12881291
Capabilities: protobufs.AgentCapabilities_AgentCapabilities_AcceptsPackages |
1289-
protobufs.AgentCapabilities_AgentCapabilities_ReportsPackageStatuses,
1292+
protobufs.AgentCapabilities_AgentCapabilities_ReportsPackageStatuses,
12901293
}
12911294
prepareClient(t, &settings, client)
12921295

@@ -1309,7 +1312,7 @@ func verifyUpdatePackages(t *testing.T, testCase packageTestCase) {
13091312
// ---> Server
13101313
// Wait for the expected package statuses to be received.
13111314
srv.EventuallyExpect("full PackageStatuses", func(msg *protobufs.AgentToServer) (*protobufs.ServerToAgent,
1312-
bool) {
1315+
bool) {
13131316
return assertPackageStatus(t, testCase, msg)
13141317
})
13151318

@@ -1470,7 +1473,7 @@ func TestMissingCapabilities(t *testing.T) {
14701473
assert.Nil(t, msg.PackagesAvailable)
14711474
},
14721475
OnOpampConnectionSettingsFunc: func(
1473-
ctx context.Context, settings *protobufs.OpAMPConnectionSettings,
1476+
ctx context.Context, settings *protobufs.OpAMPConnectionSettings,
14741477
) error {
14751478
assert.Fail(t, "should not be called since capability is not set to accept it")
14761479
return nil
@@ -1532,7 +1535,7 @@ func TestMissingPackagesStateProvider(t *testing.T) {
15321535
settings := types.StartSettings{
15331536
Callbacks: types.CallbacksStruct{},
15341537
Capabilities: protobufs.AgentCapabilities_AgentCapabilities_AcceptsPackages |
1535-
protobufs.AgentCapabilities_AgentCapabilities_ReportsPackageStatuses,
1538+
protobufs.AgentCapabilities_AgentCapabilities_ReportsPackageStatuses,
15361539
}
15371540
prepareClient(t, &settings, client)
15381541

@@ -1590,7 +1593,7 @@ func TestOfferUpdatedVersion(t *testing.T) {
15901593
},
15911594
PackagesStateProvider: localPackageState,
15921595
Capabilities: protobufs.AgentCapabilities_AgentCapabilities_AcceptsPackages |
1593-
protobufs.AgentCapabilities_AgentCapabilities_ReportsPackageStatuses,
1596+
protobufs.AgentCapabilities_AgentCapabilities_ReportsPackageStatuses,
15941597
}
15951598
prepareClient(t, &settings, client)
15961599

@@ -1612,7 +1615,7 @@ func TestOfferUpdatedVersion(t *testing.T) {
16121615
// ---> Server
16131616
// Wait for the expected package statuses to be received.
16141617
srv.EventuallyExpect("full PackageStatuses", func(msg *protobufs.AgentToServer) (*protobufs.ServerToAgent,
1615-
bool) {
1618+
bool) {
16161619
return assertPackageStatus(t, testCase, msg)
16171620
})
16181621

@@ -1639,7 +1642,7 @@ func TestOfferUpdatedVersion(t *testing.T) {
16391642
// ---> Server
16401643
// Wait for the expected package statuses to be received.
16411644
srv.EventuallyExpect("full PackageStatuses updated version", func(msg *protobufs.AgentToServer) (*protobufs.ServerToAgent,
1642-
bool) {
1645+
bool) {
16431646
return assertPackageStatus(t, testCase, msg)
16441647
})
16451648

0 commit comments

Comments
 (0)