| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "testing" |
| 6 | |
| 7 | "reasonix/internal/extension" |
| 8 | ) |
| 9 | |
| 10 | func TestTrackPublishedHostStreamUsesContextOwner(t *testing.T) { |
| 11 | first := extension.NewRuntimeOwner() |
| 12 | second := extension.NewRuntimeOwner() |
| 13 | first.Gate.Publish(1) |
| 14 | second.Gate.Publish(2) |
| 15 | |
| 16 | streamCtx, cancel := context.WithCancel(context.Background()) |
| 17 | untrack := trackPublishedHostStream(extension.ContextWithRuntimeOwner(streamCtx, first), cancel) |
| 18 | defer untrack() |
| 19 | |
| 20 | second.Gate.ForceExpireDrain(2) |
| 21 | select { |
| 22 | case <-streamCtx.Done(): |
| 23 | t.Fatal("sibling owner cancelled this runtime's host stream") |
| 24 | default: |
| 25 | } |
| 26 | first.Gate.ForceExpireDrain(1) |
| 27 | select { |
| 28 | case <-streamCtx.Done(): |
| 29 | default: |
| 30 | t.Fatal("owning runtime did not cancel its host stream") |
| 31 | } |
| 32 | } |
| 33 |