Skip to content
quarry Artifact [cdc7f7dcfe]
Login

Artifact [cdc7f7dcfe]

Artifact cdc7f7dcfe7a87c70dc8bbc8f3c179999552c8189a6b222ba96ca43b6f13f363:


package children

import (
	"context"
	"testing"
)

// The set lists what is running, oldest first, each with what started
// it, and forgets a child once it is done.
func TestRunningNamesWhatStartedEachChild(t *testing.T) {
	s := New(func(string, ...any) {})
	_, doneA, err := s.CommandFor(context.Background(), "fossil", "timeline", "GET /r/fossil/timeline", "true")
	if err != nil {
		t.Fatal(err)
	}
	_, doneB, _ := s.CommandFor(context.Background(), "tcl", "ls", "ingest", "true")
	_, doneC, _ := s.Command(context.Background(), "sqlite", "cat", "true")
	got := s.Running()
	if len(got) != 3 {
		t.Fatalf("FAIL: %d running, want 3: %+v", len(got), got)
	}
	if got[0].Repo != "fossil" || got[0].Cause != "GET /r/fossil/timeline" || got[1].Cause != "ingest" || got[2].Cause != "" {
		t.Errorf("FAIL: running reads %+v", got)
	}
	for i := 1; i < len(got); i++ {
		if got[i].Start.Before(got[i-1].Start) {
			t.Errorf("FAIL: not oldest first: %+v", got)
		}
	}
	doneA()
	doneB()
	doneC()
	if n := len(s.Running()); n != 0 {
		t.Errorf("FAIL: %d still listed after every child ended", n)
	}
}