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

[DATA-549] Remove sleeps from slam tests #1480

Merged
merged 1 commit into from
Oct 12, 2022
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
6 changes: 4 additions & 2 deletions services/slam/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,13 +633,15 @@ func (slamSvc *builtIn) StartDataProcess(
case slam.Dense:
if _, err := slamSvc.getAndSaveDataDense(cancelCtx, cams); err != nil {
slamSvc.logger.Warn(err)
} else if c != nil {
}
if c != nil {
c <- 1
}
case slam.Sparse:
if _, err := slamSvc.getAndSaveDataSparse(cancelCtx, cams, camStreams); err != nil {
slamSvc.logger.Warn(err)
} else if c != nil {
}
if c != nil {
c <- 1
}
default:
Expand Down
17 changes: 8 additions & 9 deletions services/slam/builtin/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"sync"
"sync/atomic"
"testing"
"time"

"github.com/edaniels/golog"
"github.com/edaniels/gostream"
Expand Down Expand Up @@ -699,14 +698,14 @@ func TestCartographerDataProcess(t *testing.T) {
}()

cancelCtx, cancelFunc := context.WithCancel(context.Background())
slamSvc.StartDataProcess(cancelCtx, cams, camStreams, nil)

time.Sleep(time.Millisecond * time.Duration(validDataRateMS*2))
c := make(chan int)
slamSvc.StartDataProcess(cancelCtx, cams, camStreams, c)

<-c
allObs := obs.All()
latestLoggedEntry := allObs[len(allObs)-1]
test.That(t, fmt.Sprint(latestLoggedEntry), test.ShouldContainSubstring, "bad_lidar")
cancelFunc()
test.That(t, fmt.Sprint(latestLoggedEntry), test.ShouldContainSubstring, "bad_lidar")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm also moving this check below the call to cancelFunc() so that cancelFunc() will be called even if this check fails.

})

test.That(t, utils.TryClose(context.Background(), svc), test.ShouldBeNil)
Expand Down Expand Up @@ -789,14 +788,14 @@ func TestORBSLAMDataProcess(t *testing.T) {
}()

cancelCtx, cancelFunc := context.WithCancel(context.Background())
slamSvc.StartDataProcess(cancelCtx, cams, camStreams, nil)

time.Sleep(time.Millisecond * time.Duration(validDataRateMS*2))
c := make(chan int)
slamSvc.StartDataProcess(cancelCtx, cams, camStreams, c)

<-c
obsAll := obs.All()
latestLoggedEntry := obsAll[len(obsAll)-1]
test.That(t, fmt.Sprint(latestLoggedEntry), test.ShouldContainSubstring, "bad_camera")
cancelFunc()
test.That(t, fmt.Sprint(latestLoggedEntry), test.ShouldContainSubstring, "bad_camera")
})

test.That(t, utils.TryClose(context.Background(), svc), test.ShouldBeNil)
Expand Down