Wait for Namespace runner terminal state
This commit is contained in:
parent
de32d8390e
commit
4d7c19e593
3 changed files with 44 additions and 2 deletions
|
|
@ -284,22 +284,28 @@ func instanceStopped(output string) bool {
|
|||
if len(payload) == 0 {
|
||||
return false
|
||||
}
|
||||
seenTerminalState := false
|
||||
for _, entry := range payload {
|
||||
if len(entry.PerResource) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, target := range entry.PerResource {
|
||||
if target.Tombstone != "" {
|
||||
seenTerminalState = true
|
||||
return true
|
||||
}
|
||||
if len(target.Container) == 0 {
|
||||
continue
|
||||
return false
|
||||
}
|
||||
for _, container := range target.Container {
|
||||
if container.Status != "stopped" && container.TerminatedAt == "" {
|
||||
return false
|
||||
}
|
||||
seenTerminalState = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
return seenTerminalState
|
||||
}
|
||||
|
||||
func (d *Dispatcher) waitForInstanceStop(ctx context.Context, runnerName, instanceID string, timeout time.Duration) bool {
|
||||
|
|
|
|||
33
services/forgejo-nsc/internal/nsc/dispatcher_test.go
Normal file
33
services/forgejo-nsc/internal/nsc/dispatcher_test.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package nsc
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestInstanceStoppedRequiresObservedTerminalState(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
output string
|
||||
want bool
|
||||
}{
|
||||
{name: "empty output", output: "", want: false},
|
||||
{name: "empty response", output: "[]", want: false},
|
||||
{name: "no resources yet", output: `[{"per_resource":{}}]`, want: false},
|
||||
{name: "resource without containers", output: `[{"per_resource":{"runner":{}}}]`, want: false},
|
||||
{name: "running container", output: `[{"per_resource":{"runner":{"container":[{"status":"running"}]}}}]`, want: false},
|
||||
{name: "stopped container", output: `[{"per_resource":{"runner":{"container":[{"status":"stopped"}]}}}]`, want: true},
|
||||
{name: "terminated container", output: `[{"per_resource":{"runner":{"container":[{"status":"running","terminated_at":"2026-06-07T15:00:00Z"}]}}}]`, want: true},
|
||||
{name: "tombstone", output: `[{"per_resource":{"runner":{"tombstone":"destroyed"}}}]`, want: true},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := instanceStopped(tc.output)
|
||||
if got != tc.want {
|
||||
t.Fatalf("instanceStopped(%s) = %v, want %v", tc.output, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue