Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow *Testing.T argument before context #3800

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions components/arm/universalrobots/ur.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,12 @@ func urArmConnect(ctx context.Context, conf resource.Config, logger logging.Logg
newArm.isConnected = true
newArm.mu.Unlock()
break
} else {
newArm.mu.Lock()
newArm.isConnected = false
newArm.mu.Unlock()
}

newArm.mu.Lock()
newArm.isConnected = false
newArm.mu.Unlock()

if !goutils.SelectContextOrWait(cancelCtx, 1*time.Second) {
return
}
Expand Down
6 changes: 2 additions & 4 deletions components/input/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,8 @@ func (c *client) connectStream(ctx context.Context) {
c.logger.CError(ctx, err)
if utils.SelectContextOrWait(ctx, 3*time.Second) {
continue
} else {
return
}
return
}

c.mu.RLock()
Expand Down Expand Up @@ -292,9 +291,8 @@ func (c *client) connectStream(ctx context.Context) {
if utils.SelectContextOrWait(ctx, 3*time.Second) {
c.logger.CError(ctx, err)
break
} else {
return
}
return
}
if err != nil {
c.logger.CError(ctx, err)
Expand Down
19 changes: 8 additions & 11 deletions components/input/gamepad/gamepad_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ func createController(_ context.Context, name resource.Name, logger logging.Logg
g.logger.Error(err)
}
continue
} else {
g.logger.Error(err)
return
}
g.logger.Error(err)
return
}
g.eventDispatcher(ctxWithCancel)
}
Expand Down Expand Up @@ -310,10 +309,9 @@ func (g *gamepad) connectDev(ctx context.Context) error {
g.Model = g.dev.Name()
g.Mapping = mapping
break
} else {
if err := dev.Close(); err != nil {
return err
}
}
if err := dev.Close(); err != nil {
return err
}
}

Expand All @@ -332,10 +330,9 @@ func (g *gamepad) connectDev(ctx context.Context) error {
g.Model = g.dev.Name()
g.Mapping, _ = MappingForModel(defaultMapping)
break
} else {
if err := dev.Close(); err != nil {
return err
}
}
if err := dev.Close(); err != nil {
return err
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions components/motor/dmc4000/dmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,15 @@ func (c *controller) sendCmd(cmd string) (string, error) {
if c.testChan != nil {
ret = []byte(<-c.testChan)
break
} else {
n, err := c.port.Read(buf)
if err != nil {
return string(ret), err
}
ret = append(ret, buf[:n]...)
if bytes.ContainsAny(buf[:n], ":?") {
break
}
}

n, err := c.port.Read(buf)
if err != nil {
return string(ret), err
}
ret = append(ret, buf[:n]...)
if bytes.ContainsAny(buf[:n], ":?") {
break
}
}
if bytes.LastIndexByte(ret, []byte(":")[0]) == len(ret)-1 {
Expand Down
5 changes: 2 additions & 3 deletions components/movementsensor/gpsrtkserial/gpsrtkserial.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,9 @@ func (g *rtkSerial) getNtripFromVRS() error {
if strings.HasPrefix(string(line), "HTTP/1.1 ") {
if strings.Contains(string(line), "200 OK") {
break
} else {
g.logger.Errorf("Bad HTTP response: %v", string(line))
return err
}
g.logger.Errorf("Bad HTTP response: %v", string(line))
return err
}
}

Expand Down
2 changes: 1 addition & 1 deletion config/testutils/fake_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type configAndCerts struct {
}

// NewFakeCloudServer creates and starts a new grpc server for the Viam Cloud.
func NewFakeCloudServer(t *testing.T, ctx context.Context, logger logging.Logger) (*FakeCloudServer, func()) { //nolint:revive
func NewFakeCloudServer(t *testing.T, ctx context.Context, logger logging.Logger) (*FakeCloudServer, func()) {
t.Helper()

listener, err := net.ListenTCP("tcp", &net.TCPAddr{Port: 0})
Expand Down
32 changes: 32 additions & 0 deletions etc/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,38 @@ linters-settings:
- fieldalignment
- shadow
- composites
revive:
# Unfortunately configuring a single rules disables all other rules, even
# if we set `enable-all: true`
#
# To get around this, we include default rules:
# https://github.com/mgechev/revive/blob/master/defaults.toml
rules:
- name: blank-imports
- name: context-as-argument
disabled: false
arguments:
- allowTypesBefore: "testing.TB,*testing.T,*testing.B,*testing.F"
- name: context-keys-type
- name: dot-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unreachable-code
- name: var-declaration
- name: var-naming
lll:
line-length: 140
issues:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ func TestComplexModule(t *testing.T) {
test.That(t, server.Stop(), test.ShouldBeNil)
}()
break
} else {
server.Stop()
}
server.Stop()
}
test.That(t, success, test.ShouldBeTrue)

Expand Down Expand Up @@ -395,9 +394,8 @@ func TestValidationFailure(t *testing.T) {
test.That(t, server.Stop(), test.ShouldBeNil)
}()
break
} else {
server.Stop()
}
server.Stop()
}
test.That(t, success, test.ShouldBeTrue)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ func TestComplexModules(t *testing.T) {
test.That(t, server.Stop(), test.ShouldBeNil)
}()
break
} else {
server.Stop()
}
server.Stop()
}
test.That(t, success, test.ShouldBeTrue)

Expand Down
18 changes: 8 additions & 10 deletions examples/customresources/demos/remoteserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ func TestGizmo(t *testing.T) {
logger.Infow("Port in use. Restarting on new port.", "port", port, "err", err)
test.That(t, remoteB.Close(context.Background()), test.ShouldBeNil)
continue
} else {
test.That(t, err, test.ShouldBeNil)
defer func() {
test.That(t, remoteB.Close(context.Background()), test.ShouldBeNil)
}()
break
}
test.That(t, err, test.ShouldBeNil)
defer func() {
test.That(t, remoteB.Close(context.Background()), test.ShouldBeNil)
}()
break
}

// Create remote A. Loop to ensure we find an available port.
Expand Down Expand Up @@ -102,11 +101,10 @@ func TestGizmo(t *testing.T) {
test.That(t, pmgr.Stop(), test.ShouldBeNil)
}()
break
} else {
logger.Infow("Port in use. Restarting on new port.", "port", port, "err", err)
pmgr.Stop()
continue
}
logger.Infow("Port in use. Restarting on new port.", "port", port, "err", err)
pmgr.Stop()
continue
}
test.That(t, success, test.ShouldBeTrue)

Expand Down
7 changes: 3 additions & 4 deletions module/module_interceptors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ func TestOpID(t *testing.T) {
test.That(t, server.Stop(), test.ShouldBeNil)
}()
break
} else {
logger.Infow("Port in use. Restarting on new port.", "port", port, "err", err)
server.Stop()
continue
}
logger.Infow("Port in use. Restarting on new port.", "port", port, "err", err)
server.Stop()
continue
}
test.That(t, success, test.ShouldBeTrue)

Expand Down
9 changes: 4 additions & 5 deletions motionplan/cBiRRT.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,11 @@ func (mp *cBiRRTMotionPlanner) constrainedExtend(
qstep[i] = q * 2.0
}
continue
} else {
// We've arrived back at very nearly the same configuration again; stop solving and send back oldNear.
// Do not add the near-identical configuration to the RRT map
mchan <- oldNear
return
}
// We've arrived back at very nearly the same configuration again; stop solving and send back oldNear.
// Do not add the near-identical configuration to the RRT map
mchan <- oldNear
return
}
if doubled {
copy(qstep, mp.planOpts.qstep)
Expand Down
24 changes: 11 additions & 13 deletions pointcloud/voxel_segmentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@ func (vg *VoxelGrid) GetPlanesFromLabels() ([]Plane, PointCloud, error) {
for p, d := range vox.Points {
if _, ok := seen[p]; ok { // already assigned point to another label
continue
} else {
seen[p] = true
if _, ok := pointsByLabel[vox.Label]; !ok {
pointsByLabel[vox.Label] = make(map[r3.Vector]Data)
}
pointsByLabel[vox.Label][p] = d
}
seen[p] = true
if _, ok := pointsByLabel[vox.Label]; !ok {
pointsByLabel[vox.Label] = make(map[r3.Vector]Data)
}
pointsByLabel[vox.Label][p] = d
}
} else if len(vox.Points) == len(vox.PointLabels) {
// voxel has points for either no plane or at least two planes
Expand All @@ -95,14 +94,13 @@ func (vg *VoxelGrid) GetPlanesFromLabels() ([]Plane, PointCloud, error) {
for p, d := range vox.Points {
if _, ok := seen[p]; ok { // already assigned point to another label
continue
} else {
seen[p] = true
ptLabel := vox.PointLabels[i]
if _, ok := pointsByLabel[ptLabel]; !ok {
pointsByLabel[ptLabel] = make(map[r3.Vector]Data)
}
pointsByLabel[ptLabel][p] = d
}
seen[p] = true
ptLabel := vox.PointLabels[i]
if _, ok := pointsByLabel[ptLabel]; !ok {
pointsByLabel[ptLabel] = make(map[r3.Vector]Data)
}
pointsByLabel[ptLabel][p] = d
i++
}
}
Expand Down
10 changes: 4 additions & 6 deletions robot/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,12 @@ func (rc *RobotClient) checkConnection(ctx context.Context, checkEvery, reconnec
// if pipe is closed, we know for sure we lost connection
if isClosedPipeError(err) {
break
} else {
// otherwise retry
continue
}
} else {
outerError = nil
break
// otherwise retry
continue
}
outerError = nil
break
}
if outerError != nil {
rc.Logger().CErrorw(ctx,
Expand Down
3 changes: 1 addition & 2 deletions services/motion/builtin/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ func TestState(t *testing.T) {
return nil, errors.New("planning failed")
},
executeFunc: func(ctx context.Context, plan motionplan.Plan) (state.ExecuteResponse, error) {
t.Log("should not be called as planning failed")
t.FailNow()
t.Fatal("should not be called as planning failed") //nolint:revive
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keeping as is with a nolint since this effects benchmarks


if err := ctx.Err(); err != nil {
return state.ExecuteResponse{}, err
Expand Down
13 changes: 6 additions & 7 deletions vision/classification/classification_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ func Overlay(img image.Image, classifications Classifications) (image.Image, err
// Skip unknown labels generated by Viam-trained models.
if classification.Label() == "VIAM_UNKNOWN" {
continue
} else {
rimage.DrawString(gimg,
fmt.Sprintf("%v: %.2f", classification.Label(), classification.Score()),
image.Point{x, y},
color.NRGBA{255, 0, 0, 255},
30)
y += 30
}
rimage.DrawString(gimg,
fmt.Sprintf("%v: %.2f", classification.Label(), classification.Score()),
image.Point{x, y},
color.NRGBA{255, 0, 0, 255},
30)
y += 30
}
return gimg.Image(), nil
}
3 changes: 1 addition & 2 deletions vision/segmentation/plane_segmentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,8 @@ func (pcps *pointCloudPlaneSegmentation) FindPlanes(ctx context.Context) ([]pc.P
// this cloud is not valid so revert to last
nonPlaneCloud = lastNonPlaneCloud
break
} else {
nonPlaneCloud = smallerNonPlaneCloud
}
nonPlaneCloud = smallerNonPlaneCloud
planes = append(planes, smallerPlane)
}
return planes, nonPlaneCloud, nil
Expand Down
7 changes: 3 additions & 4 deletions web/server/entrypoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ func TestEntrypoint(t *testing.T) {
test.That(t, server.Stop(), test.ShouldBeNil)
}()
break
} else {
logger.Infow("Port in use. Restarting on new port.", "port", port, "err", err)
server.Stop()
continue
}
logger.Infow("Port in use. Restarting on new port.", "port", port, "err", err)
server.Stop()
continue
}
test.That(t, success, test.ShouldBeTrue)

Expand Down
Loading