Skip to content

Commit

Permalink
Make sensors service not configured on default (#4428)
Browse files Browse the repository at this point in the history
  • Loading branch information
randhid authored Oct 8, 2024
1 parent c279b0b commit f9359fe
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 215 deletions.
56 changes: 4 additions & 52 deletions robot/impl/local_robot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ func TestConfigRemote(t *testing.T) {

expected := []resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("squee:pieceArm"),
arm.Named("foo:pieceArm"),
arm.Named("bar:pieceArm"),
Expand All @@ -204,11 +203,8 @@ func TestConfigRemote(t *testing.T) {
gripper.Named("foo:pieceGripper"),
gripper.Named("bar:pieceGripper"),
motion.Named("squee:builtin"),
sensors.Named("squee:builtin"),
motion.Named("foo:builtin"),
sensors.Named("foo:builtin"),
motion.Named("bar:builtin"),
sensors.Named("bar:builtin"),
}

resources2 := r2.ResourceNames()
Expand Down Expand Up @@ -424,7 +420,6 @@ func TestConfigRemoteWithAuth(t *testing.T) {

expected := []resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("bar:pieceArm"),
arm.Named("foo:pieceArm"),
audioinput.Named("bar:mic1"),
Expand All @@ -438,9 +433,7 @@ func TestConfigRemoteWithAuth(t *testing.T) {
gripper.Named("bar:pieceGripper"),
gripper.Named("foo:pieceGripper"),
motion.Named("foo:builtin"),
sensors.Named("foo:builtin"),
motion.Named("bar:builtin"),
sensors.Named("bar:builtin"),
}

resources2 := r2.ResourceNames()
Expand Down Expand Up @@ -595,15 +588,13 @@ func TestConfigRemoteWithTLSAuth(t *testing.T) {

expected := []resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("foo:pieceArm"),
audioinput.Named("foo:mic1"),
camera.Named("foo:cameraOver"),
movementsensor.Named("foo:movement_sensor1"),
movementsensor.Named("foo:movement_sensor2"),
gripper.Named("foo:pieceGripper"),
motion.Named("foo:builtin"),
sensors.Named("foo:builtin"),
}

resources2 := r2.ResourceNames()
Expand Down Expand Up @@ -835,7 +826,7 @@ func TestMetadataUpdate(t *testing.T) {
resources := r.ResourceNames()
test.That(t, err, test.ShouldBeNil)

test.That(t, len(resources), test.ShouldEqual, 8)
test.That(t, len(resources), test.ShouldEqual, 7)
test.That(t, err, test.ShouldBeNil)

// 5 declared resources + default sensors
Expand All @@ -847,7 +838,6 @@ func TestMetadataUpdate(t *testing.T) {
movementsensor.Named("movement_sensor1"),
movementsensor.Named("movement_sensor2"),
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
}

resources = r.ResourceNames()
Expand All @@ -859,32 +849,6 @@ func TestMetadataUpdate(t *testing.T) {
test.That(t, resources, test.ShouldBeEmpty)
}

func TestSensorsService(t *testing.T) {
logger := logging.NewTestLogger(t)
cfg, err := config.Read(context.Background(), "data/fake.json", logger)
test.That(t, err, test.ShouldBeNil)

r := setupLocalRobot(t, context.Background(), cfg, logger)

svc, err := sensors.FromRobot(r, resource.DefaultServiceName)
test.That(t, err, test.ShouldBeNil)

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)
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)
test.That(t, len(readings), test.ShouldEqual, 1)
test.That(t, readings[0].Name, test.ShouldResemble, movementsensor.Named("movement_sensor1"))
test.That(t, len(readings[0].Readings), test.ShouldBeGreaterThan, 3)

readings, err = svc.Readings(context.Background(), sensorNames, map[string]interface{}{})
test.That(t, err, test.ShouldBeNil)
test.That(t, len(readings), test.ShouldEqual, 2)
}

func TestStatusService(t *testing.T) {
logger := logging.NewTestLogger(t)
cfg, err := config.Read(context.Background(), "data/fake.json", logger)
Expand Down Expand Up @@ -1062,7 +1026,7 @@ func TestStatus(t *testing.T) {
test.That(t, err, test.ShouldBeNil)
// 5 because the 3 default services are always added to a local_robot. We only care
// about the first two (working1 and button1) however.
test.That(t, len(resp), test.ShouldEqual, 4)
test.That(t, len(resp), test.ShouldEqual, 3)

// although the response is length 5, the only thing we actually care about for testing
// is consistency with the expected values in the workingResourceMap. So we eliminate
Expand Down Expand Up @@ -1178,7 +1142,6 @@ func TestStatusRemote(t *testing.T) {
r.ResourceNames(),
[]resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("foo:arm1"),
arm.Named("foo:arm2"),
arm.Named("bar:arm1"),
Expand Down Expand Up @@ -1286,7 +1249,6 @@ func TestGetRemoteResourceAndGrandFather(t *testing.T) {
r.ResourceNames(),
[]resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("remote:foo:arm1"), arm.Named("remote:foo:arm2"),
arm.Named("remote:pieceArm"),
arm.Named("remote:foo:pieceArm"),
Expand All @@ -1296,9 +1258,7 @@ func TestGetRemoteResourceAndGrandFather(t *testing.T) {
movementsensor.Named("remote:movement_sensor2"),
gripper.Named("remote:pieceGripper"),
motion.Named("remote:builtin"),
sensors.Named("remote:builtin"),
motion.Named("remote:foo:builtin"),
sensors.Named("remote:foo:builtin"),
},
)
arm1, err := r.ResourceByName(arm.Named("remote:foo:arm1"))
Expand Down Expand Up @@ -1770,7 +1730,7 @@ func TestConfigMethod(t *testing.T) {
// Assert that Config method returns the two default services: motion and sensors.
actualCfg := r.Config()
defaultSvcs := removeDefaultServices(actualCfg)
test.That(t, len(defaultSvcs), test.ShouldEqual, 2)
test.That(t, len(defaultSvcs), test.ShouldEqual, 1)
for _, svc := range defaultSvcs {
test.That(t, svc.API.SubtypeName, test.ShouldBeIn,
motion.API.SubtypeName, sensors.API.SubtypeName)
Expand Down Expand Up @@ -1875,7 +1835,7 @@ func TestConfigMethod(t *testing.T) {
// Assert that default motion and sensor services are still present, but data
// manager default service has been replaced by the "fake1" data manager service.
defaultSvcs = removeDefaultServices(actualCfg)
test.That(t, len(defaultSvcs), test.ShouldEqual, 2)
test.That(t, len(defaultSvcs), test.ShouldEqual, 1)
for _, svc := range defaultSvcs {
test.That(t, svc.API.SubtypeName, test.ShouldBeIn, motion.API.SubtypeName,
sensors.API.SubtypeName)
Expand Down Expand Up @@ -3445,14 +3405,6 @@ func getExpectedDefaultStatuses(revision string) []resource.Status {
State: resource.NodeStateReady,
Revision: revision,
},
{
Name: resource.Name{
API: resource.APINamespaceRDK.WithServiceType("sensors"),
Name: "builtin",
},
State: resource.NodeStateReady,
Revision: revision,
},
}
}

Expand Down
3 changes: 0 additions & 3 deletions robot/impl/robot_framesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
_ "go.viam.com/rdk/services/datamanager/builtin"
"go.viam.com/rdk/services/motion"
_ "go.viam.com/rdk/services/motion/builtin"
"go.viam.com/rdk/services/sensors"
_ "go.viam.com/rdk/services/sensors/builtin"
"go.viam.com/rdk/spatialmath"
"go.viam.com/rdk/testutils/robottestutils"
rutils "go.viam.com/rdk/utils"
Expand Down Expand Up @@ -129,7 +127,6 @@ func TestFrameSystemConfigWithRemote(t *testing.T) {

finalSet := []resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
base.Named("foo"),
gripper.Named("myParentIsRemote"),
}
Expand Down
27 changes: 0 additions & 27 deletions robot/impl/robot_reconfigure_remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
// TODO(RSDK-7884): change everything that depends on this import to a mock.
"go.viam.com/rdk/services/motion"
// TODO(RSDK-7884): change all referenced resources to mocks.
"go.viam.com/rdk/services/sensors"
rdktestutils "go.viam.com/rdk/testutils"
"go.viam.com/rdk/testutils/robottestutils"
)
Expand Down Expand Up @@ -109,11 +108,9 @@ func TestRemoteRobotsGold(t *testing.T) {
r.ResourceNames(),
[]resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("arm1"),
arm.Named("foo:remoteArm"),
motion.Named("foo:builtin"),
sensors.Named("foo:builtin"),
},
)

Expand All @@ -123,15 +120,12 @@ func TestRemoteRobotsGold(t *testing.T) {

mainPartAndFooAndBarResources := []resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("arm1"),
arm.Named("arm2"),
arm.Named("foo:remoteArm"),
motion.Named("foo:builtin"),
sensors.Named("foo:builtin"),
arm.Named("bar:remoteArm"),
motion.Named("bar:builtin"),
sensors.Named("bar:builtin"),
}
testutils.WaitForAssertionWithSleep(t, time.Millisecond*100, 300, func(tb testing.TB) {
rdktestutils.VerifySameResourceNames(tb, r.ResourceNames(), mainPartAndFooAndBarResources)
Expand All @@ -143,11 +137,9 @@ func TestRemoteRobotsGold(t *testing.T) {
verifyReachableResourceNames(tb, r,
[]resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("arm1"),
arm.Named("foo:remoteArm"),
motion.Named("foo:builtin"),
sensors.Named("foo:builtin"),
},
)
})
Expand Down Expand Up @@ -214,19 +206,14 @@ func TestRemoteRobotsUpdate(t *testing.T) {

expectedSet := []resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("foo:arm1"),
motion.Named("foo:builtin"),
sensors.Named("foo:builtin"),
arm.Named("bar:arm1"),
motion.Named("bar:builtin"),
sensors.Named("bar:builtin"),
arm.Named("hello:arm1"),
motion.Named("hello:builtin"),
sensors.Named("hello:builtin"),
arm.Named("world:arm1"),
motion.Named("world:builtin"),
sensors.Named("world:builtin"),
}
testutils.WaitForAssertionWithSleep(t, time.Millisecond*100, 300, func(tb testing.TB) {
rdktestutils.VerifySameResourceNames(tb, r.ResourceNames(), expectedSet)
Expand All @@ -238,7 +225,6 @@ func TestRemoteRobotsUpdate(t *testing.T) {
verifyReachableResourceNames(tb, r,
[]resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
},
)
})
Expand Down Expand Up @@ -291,11 +277,9 @@ func TestInferRemoteRobotDependencyConnectAtStartup(t *testing.T) {
r := setupLocalRobot(t, ctx, localConfig, logger.Sublogger("local"))
expectedSet := []resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("arm1"),
arm.Named("foo:pieceArm"),
motion.Named("foo:builtin"),
sensors.Named("foo:builtin"),
}

rdktestutils.VerifySameResourceNames(t, r.ResourceNames(), expectedSet)
Expand All @@ -306,7 +290,6 @@ func TestInferRemoteRobotDependencyConnectAtStartup(t *testing.T) {
verifyReachableResourceNames(tb, r,
[]resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
},
)
})
Expand Down Expand Up @@ -374,19 +357,16 @@ func TestInferRemoteRobotDependencyConnectAfterStartup(t *testing.T) {
rdktestutils.VerifySameResourceNames(t, r.ResourceNames(),
[]resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
},
)
err := foo.StartWeb(ctx, options)
test.That(t, err, test.ShouldBeNil)

expectedSet := []resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("arm1"),
arm.Named("foo:pieceArm"),
motion.Named("foo:builtin"),
sensors.Named("foo:builtin"),
}
testutils.WaitForAssertionWithSleep(t, time.Millisecond*100, 300, func(tb testing.TB) {
rdktestutils.VerifySameResourceNames(tb, r.ResourceNames(), expectedSet)
Expand All @@ -398,7 +378,6 @@ func TestInferRemoteRobotDependencyConnectAfterStartup(t *testing.T) {
verifyReachableResourceNames(tb, r,
[]resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
},
)
})
Expand Down Expand Up @@ -463,13 +442,10 @@ func TestInferRemoteRobotDependencyAmbiguous(t *testing.T) {

expectedSet := []resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("foo:pieceArm"),
motion.Named("foo:builtin"),
sensors.Named("foo:builtin"),
arm.Named("bar:pieceArm"),
motion.Named("bar:builtin"),
sensors.Named("bar:builtin"),
}

rdktestutils.VerifySameResourceNames(t, r.ResourceNames(), expectedSet)
Expand Down Expand Up @@ -507,13 +483,10 @@ func TestInferRemoteRobotDependencyAmbiguous(t *testing.T) {

finalSet := []resource.Name{
motion.Named(resource.DefaultServiceName),
sensors.Named(resource.DefaultServiceName),
arm.Named("foo:pieceArm"),
motion.Named("foo:builtin"),
sensors.Named("foo:builtin"),
arm.Named("bar:pieceArm"),
motion.Named("bar:builtin"),
sensors.Named("bar:builtin"),
arm.Named("arm1"),
}

Expand Down
Loading

0 comments on commit f9359fe

Please sign in to comment.