Skip to content

Commit

Permalink
Test debugging QoL: compare sorted resource names instead of unordere…
Browse files Browse the repository at this point in the history
…d sets (viamrobotics#3996)
  • Loading branch information
maximpertsov authored May 28, 2024
1 parent b6cf968 commit 9e3fc52
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 409 deletions.
9 changes: 3 additions & 6 deletions robot/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,7 @@ func TestClientRefresh(t *testing.T) {
utils.NewStringSet(testutils.ExtractNames(baseNames...)...),
)

test.That(t, testutils.NewResourceNameSet(client.ResourceNames()...), test.ShouldResemble, testutils.NewResourceNameSet(
finalResources...))
testutils.VerifySameResourceNames(t, client.ResourceNames(), finalResources)

test.That(t, client.Close(context.Background()), test.ShouldBeNil)

Expand Down Expand Up @@ -801,8 +800,7 @@ func TestClientRefresh(t *testing.T) {
utils.NewStringSet(testutils.ExtractNames(baseNames...)...),
)

test.That(t, testutils.NewResourceNameSet(client.ResourceNames()...), test.ShouldResemble, testutils.NewResourceNameSet(
emptyResources...))
testutils.VerifySameResourceNames(t, client.ResourceNames(), emptyResources)

mu.Lock()
injectRobot.ResourceRPCAPIsFunc = func() []resource.RPCAPI { return nil }
Expand All @@ -825,8 +823,7 @@ func TestClientRefresh(t *testing.T) {
utils.NewStringSet(testutils.ExtractNames(baseNames...)...),
)

test.That(t, testutils.NewResourceNameSet(client.ResourceNames()...), test.ShouldResemble, testutils.NewResourceNameSet(
finalResources...))
testutils.VerifySameResourceNames(t, client.ResourceNames(), finalResources)

test.That(t, client.Close(context.Background()), test.ShouldBeNil)
})
Expand Down
43 changes: 13 additions & 30 deletions robot/impl/local_robot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,7 @@ func TestConfigRemote(t *testing.T) {

resources2 := r2.ResourceNames()

test.That(
t,
rtestutils.NewResourceNameSet(resources2...),
test.ShouldResemble,
rtestutils.NewResourceNameSet(expected...),
)
rtestutils.VerifySameResourceNames(t, resources2, expected)

expectedRemotes := []string{"squee", "foo", "bar"}
remotes2 := r2.RemoteNames()
Expand Down Expand Up @@ -443,12 +438,7 @@ func TestConfigRemoteWithAuth(t *testing.T) {

resources2 := r2.ResourceNames()

test.That(
t,
rtestutils.NewResourceNameSet(resources2...),
test.ShouldResemble,
rtestutils.NewResourceNameSet(expected...),
)
rtestutils.VerifySameResourceNames(t, resources2, expected)

remotes2 := r2.RemoteNames()
expectedRemotes := []string{"bar", "foo"}
Expand Down Expand Up @@ -615,12 +605,7 @@ func TestConfigRemoteWithTLSAuth(t *testing.T) {

resources2 := r2.ResourceNames()

test.That(
t,
rtestutils.NewResourceNameSet(resources2...),
test.ShouldResemble,
rtestutils.NewResourceNameSet(expected...),
)
rtestutils.VerifySameResourceNames(t, resources2, expected)

remotes2 := r2.RemoteNames()
expectedRemotes := []string{"foo"}
Expand Down Expand Up @@ -897,7 +882,7 @@ func TestMetadataUpdate(t *testing.T) {

resources = r.ResourceNames()
test.That(t, len(resources), test.ShouldEqual, len(resourceNames))
test.That(t, rtestutils.NewResourceNameSet(resources...), test.ShouldResemble, rtestutils.NewResourceNameSet(resourceNames...))
rtestutils.VerifySameResourceNames(t, resources, resourceNames)

test.That(t, r.Close(context.Background()), test.ShouldBeNil)
resources = r.ResourceNames()
Expand All @@ -917,7 +902,7 @@ func TestSensorsService(t *testing.T) {
sensorNames := []resource.Name{movementsensor.Named("movement_sensor1"), movementsensor.Named("movement_sensor2")}
foundSensors, err := svc.Sensors(context.Background(), map[string]interface{}{})
test.That(t, err, test.ShouldBeNil)
test.That(t, rtestutils.NewResourceNameSet(foundSensors...), test.ShouldResemble, rtestutils.NewResourceNameSet(sensorNames...))
rtestutils.VerifySameResourceNames(t, foundSensors, sensorNames)

readings, err := svc.Readings(context.Background(), []resource.Name{movementsensor.Named("movement_sensor1")}, map[string]interface{}{})
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -1212,18 +1197,17 @@ func TestStatusRemote(t *testing.T) {
ctx := context.Background()
r := setupLocalRobot(t, ctx, remoteConfig, logger)

test.That(
rtestutils.VerifySameResourceNames(
t,
rtestutils.NewResourceNameSet(r.ResourceNames()...),
test.ShouldResemble,
rtestutils.NewResourceNameSet(
r.ResourceNames(),
[]resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("foo:arm1"),
arm.Named("foo:arm2"),
arm.Named("bar:arm1"),
arm.Named("bar:arm2"),
),
},
)
statuses, err := r.Status(
ctx, []resource.Name{arm.Named("foo:arm1"), arm.Named("foo:arm2"), arm.Named("bar:arm1"), arm.Named("bar:arm2")},
Expand Down Expand Up @@ -1321,11 +1305,10 @@ func TestGetRemoteResourceAndGrandFather(t *testing.T) {

r := setupLocalRobot(t, ctx, remoteConfig, logger)

test.That(
rtestutils.VerifySameResourceNames(
t,
rtestutils.NewResourceNameSet(r.ResourceNames()...),
test.ShouldResemble,
rtestutils.NewResourceNameSet(
r.ResourceNames(),
[]resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("remote:foo:arm1"), arm.Named("remote:foo:arm2"),
Expand All @@ -1340,7 +1323,7 @@ func TestGetRemoteResourceAndGrandFather(t *testing.T) {
sensors.Named("remote:builtin"),
motion.Named("remote:foo:builtin"),
sensors.Named("remote:foo:builtin"),
),
},
)
arm1, err := r.ResourceByName(arm.Named("remote:foo:arm1"))
test.That(t, err, test.ShouldBeNil)
Expand Down
41 changes: 13 additions & 28 deletions robot/impl/resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,10 @@ func TestManagerForRemoteRobot(t *testing.T) {
servoNames := []resource.Name{servo.Named("servo1"), servo.Named("servo2")}

test.That(t, manager.RemoteNames(), test.ShouldBeEmpty)
test.That(
rdktestutils.VerifySameResourceNames(
t,
rdktestutils.NewResourceNameSet(manager.ResourceNames()...),
test.ShouldResemble,
rdktestutils.NewResourceNameSet(rdktestutils.ConcatResourceNames(
manager.ResourceNames(),
rdktestutils.ConcatResourceNames(
armNames,
baseNames,
boardNames,
Expand All @@ -212,7 +211,7 @@ func TestManagerForRemoteRobot(t *testing.T) {
inputNames,
motorNames,
servoNames,
)...),
),
)

_, err := manager.ResourceByName(arm.Named("arm1"))
Expand Down Expand Up @@ -286,11 +285,10 @@ func TestManagerMergeNamesWithRemotes(t *testing.T) {
test.ShouldResemble,
utils.NewStringSet("remote1", "remote2"),
)
test.That(
rdktestutils.VerifySameResourceNames(
t,
rdktestutils.NewResourceNameSet(manager.ResourceNames()...),
test.ShouldResemble,
rdktestutils.NewResourceNameSet(rdktestutils.ConcatResourceNames(
manager.ResourceNames(),
rdktestutils.ConcatResourceNames(
armNames,
baseNames,
boardNames,
Expand All @@ -299,7 +297,7 @@ func TestManagerMergeNamesWithRemotes(t *testing.T) {
inputNames,
motorNames,
servoNames,
)...),
),
)
_, err := manager.ResourceByName(arm.Named("arm1"))
test.That(t, err, test.ShouldBeNil)
Expand Down Expand Up @@ -394,13 +392,10 @@ func TestManagerResourceRemoteName(t *testing.T) {

manager.updateRemotesResourceNames(context.Background())

res := manager.remoteResourceNames(fromRemoteNameToRemoteNodeName("remote1"))

test.That(
rdktestutils.VerifySameResourceNames(
t,
rdktestutils.NewResourceNameSet(res...),
test.ShouldResemble,
rdktestutils.NewResourceNameSet([]resource.Name{arm.Named("remote1:arm1"), arm.Named("remote1:arm2")}...),
manager.remoteResourceNames(fromRemoteNameToRemoteNodeName("remote1")),
[]resource.Name{arm.Named("remote1:arm1"), arm.Named("remote1:arm2")},
)
}

Expand Down Expand Up @@ -1888,25 +1883,15 @@ func TestReconfigureParity(t *testing.T) {
cfg = ConfigFromFile(t, initCfg)
r2 := setupLocalRobot(t, ctx, cfg, logger).(*localRobot)

test.That(
t,
rdktestutils.NewResourceNameSet(r1.ResourceNames()...),
test.ShouldResemble,
rdktestutils.NewResourceNameSet(r2.ResourceNames()...),
)
rdktestutils.VerifySameResourceNames(t, r1.ResourceNames(), r2.ResourceNames())

cfg = ConfigFromFile(t, updateCfg)
r1.Reconfigure(ctx, cfg)
cfg = ConfigFromFile(t, updateCfg)
// force robot to reconfigure resources serially
r2.reconfigure(ctx, cfg, true)

test.That(
t,
rdktestutils.NewResourceNameSet(r1.ResourceNames()...),
test.ShouldResemble,
rdktestutils.NewResourceNameSet(r2.ResourceNames()...),
)
rdktestutils.VerifySameResourceNames(t, r1.ResourceNames(), r2.ResourceNames())
})
}

Expand Down
6 changes: 3 additions & 3 deletions robot/impl/robot_framesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ func TestFrameSystemConfigWithRemote(t *testing.T) {

rr.triggerConfig <- struct{}{}

finalSet := rdktestutils.NewResourceNameSet(
finalSet := []resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
base.Named("foo"),
gripper.Named("myParentIsRemote"),
)
}
testutils.WaitForAssertionWithSleep(t, time.Millisecond*100, 300, func(tb testing.TB) {
test.That(tb, rdktestutils.NewResourceNameSet(r2.ResourceNames()...), test.ShouldResemble, finalSet)
rdktestutils.VerifySameResourceNames(tb, r2.ResourceNames(), finalSet)
})

fsCfg, err = r2.FrameSystemConfig(context.Background())
Expand Down
Loading

0 comments on commit 9e3fc52

Please sign in to comment.