Skip to content

Commit

Permalink
Add async save unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
seanavery committed Sep 23, 2024
1 parent e5d49ef commit fb50e68
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cam/cam.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (vs *videostore) DoCommand(_ context.Context, command map[string]interface{
// Async save command will run the concat operation in the background.
// It waits for the segment duration before running to ensure the last segment
// is written to storage before concatenation.
// TODO: (seanp) Optimize this to immediately run once the last segment is written.
// TODO: (seanp) Optimize this to immediately run as soon as the current segment is completed.
if async {
vs.logger.Debug("run save command asynchronously")
go func() {
Expand Down
31 changes: 31 additions & 0 deletions tests/save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ func TestSaveDoCommand(t *testing.T) {
"metadata": "test-metadata",
}

// Valid async save
saveCmd4 := map[string]interface{}{
"command": "save",
"from": "2024-09-06_15-00-33",
"to": "2024-09-06_15-01-33",
"metadata": "test-metadata",
"async": true,
}

t.Run("Test Save DoCommand Valid Range", func(t *testing.T) {
timeoutCtx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
Expand Down Expand Up @@ -175,4 +184,26 @@ func TestSaveDoCommand(t *testing.T) {
t.Fatalf("expected error for invalid datetime format")
}
})

t.Run("Test Save DoCommand Async", func(t *testing.T) {
timeoutCtx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
r, err := setupViamServer(timeoutCtx, config1)
if err != nil {
t.Fatalf("failed to setup viam server: %v", err)
}
defer r.Close(timeoutCtx)
vs, err := camera.FromRobot(r, videoStoreComponentName)
if err != nil {
t.Fatalf("failed to get video store component: %v", err)
}
res, err := vs.DoCommand(timeoutCtx, saveCmd4)
if err != nil {
t.Fatalf("failed to execute save command: %v", err)
}
_, ok := res["filename"].(string)
if !ok {
t.Fatalf("failed to parse filename from response: %v", res)
}
})
}

0 comments on commit fb50e68

Please sign in to comment.