package server

import (
	"context"
	"testing"
	"time"
)

func TestStartWikiCatalogGCWorkerStopsWithServerContext(t *testing.T) {
	ctx, cancel := context.WithCancel(context.Background())
	svc, registry, _ := newLifecycleTestService(t, ctx)

	startWikiCatalogGCWorkers(svc, registry)
	cancel()

	done := make(chan struct{})
	go func() {
		svc.Wg.Wait()
		close(done)
	}()

	select {
	case <-done:
	case <-time.After(time.Second):
		t.Fatal("wiki catalog GC worker did not stop after server context cancellation")
	}
}
