-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtracker_close_test.go
More file actions
51 lines (46 loc) · 1.28 KB
/
Copy pathtracker_close_test.go
File metadata and controls
51 lines (46 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// ABOUTME: Tests that Engine.Close cancels a cancellable interviewer it owns (#478).
package tracker
import (
"context"
"sync"
"testing"
)
type cancelSpyInterviewer struct {
mu sync.Mutex
canceled bool
}
func (c *cancelSpyInterviewer) Ask(string, []string, string) (string, error) { return "", nil }
func (c *cancelSpyInterviewer) Cancel() {
c.mu.Lock()
c.canceled = true
c.mu.Unlock()
}
func (c *cancelSpyInterviewer) wasCanceled() bool {
c.mu.Lock()
defer c.mu.Unlock()
return c.canceled
}
// TestEngine_CloseCancelsInterviewer proves the engine cancels a cancellable
// interviewer (e.g. the webhook callback server) on Close, so a library caller
// that lets the library own the interviewer doesn't leak it past the run.
func TestEngine_CloseCancelsInterviewer(t *testing.T) {
graph, err := parsePipelineSource(quickDip, "dip", SourceRef{})
if err != nil {
t.Fatalf("parse: %v", err)
}
iv := &cancelSpyInterviewer{}
eng, err := NewEngineFromGraph(context.Background(), graph, Config{
WorkingDir: t.TempDir(),
LLMClient: successStub(),
Interviewer: iv,
})
if err != nil {
t.Fatalf("NewEngineFromGraph: %v", err)
}
if err := eng.Close(); err != nil {
t.Fatalf("Close: %v", err)
}
if !iv.wasCanceled() {
t.Fatal("expected Close to cancel the interviewer")
}
}