runner.go
This commit is contained in:
@@ -2,13 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"mxl-pattern-generator/internal/audio"
|
||||
"mxl-pattern-generator/internal/flowdef"
|
||||
@@ -253,67 +250,3 @@ func TestValidateAudioArgsRejectsUnknownLevelForFlowDefinition(t *testing.T) {
|
||||
t.Fatalf("error = %v, want unsupported audio level error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunConcurrentCancelsSiblingAndWaitsForCleanup(t *testing.T) {
|
||||
wantErr := errors.New("writer failed")
|
||||
peerStarted := make(chan struct{})
|
||||
peerStopped := make(chan struct{})
|
||||
|
||||
err := runConcurrent(context.Background(),
|
||||
namedRunner{
|
||||
name: "video",
|
||||
run: func(ctx context.Context) error {
|
||||
<-peerStarted
|
||||
return wantErr
|
||||
},
|
||||
},
|
||||
namedRunner{
|
||||
name: "audio",
|
||||
run: func(ctx context.Context) error {
|
||||
close(peerStarted)
|
||||
<-ctx.Done()
|
||||
close(peerStopped)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
if !errors.Is(err, wantErr) {
|
||||
t.Fatalf("error = %v, want wrapped %v", err, wantErr)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "video flow") {
|
||||
t.Fatalf("error = %q, want runner name", err)
|
||||
}
|
||||
select {
|
||||
case <-peerStopped:
|
||||
default:
|
||||
t.Fatal("runConcurrent returned before the sibling completed cleanup")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunConcurrentParentCancellationIsGraceful(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
started := make(chan struct{})
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
done <- runConcurrent(ctx, namedRunner{
|
||||
name: "video",
|
||||
run: func(ctx context.Context) error {
|
||||
close(started)
|
||||
<-ctx.Done()
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}()
|
||||
|
||||
<-started
|
||||
cancel()
|
||||
select {
|
||||
case err := <-done:
|
||||
if err != nil {
|
||||
t.Fatalf("runConcurrent: %v", err)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("runConcurrent did not stop after parent cancellation")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user