52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http/httptest"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
|
"git.a-wan.net/alan/pipelines/internal/stage"
|
|
)
|
|
|
|
func TestRunAdmissionBrowserLostResponse(t *testing.T) {
|
|
if os.Getenv("PIPELINES_BROWSER_TEST") != "1" {
|
|
t.Skip("set PIPELINES_BROWSER_TEST=1 for the scratch Chrome check")
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
|
|
defer cancel()
|
|
store, err := pipeline.Open(filepath.Join(t.TempDir(), "scratch.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer store.Close()
|
|
if _, err := store.Submit(ctx, "Scratch", pipeline.Template([]string{"work"}, true)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
items, _ := store.List(ctx)
|
|
handler := Handler(ctx, store).(*runHandler)
|
|
defer func() { cancel(); WaitRuns(handler) }()
|
|
handler.runner.execute = func(ctx context.Context, _ stage.Definition, _ stage.Values) (stage.Result, error) {
|
|
<-ctx.Done()
|
|
return stage.Result{}, ctx.Err()
|
|
}
|
|
srv := httptest.NewServer(handler)
|
|
defer srv.Close()
|
|
cmd := exec.CommandContext(ctx, "node", "../../web/test/run-admission-probe.mjs", strings.TrimPrefix(srv.URL, "http://"), fmt.Sprint(items[0].ID), t.TempDir())
|
|
if output, err := cmd.CombinedOutput(); err != nil {
|
|
t.Fatalf("lost ack browser regression: %v\n%s", err, output)
|
|
} else {
|
|
t.Log(string(output))
|
|
}
|
|
runs, err := store.ListRuns(ctx)
|
|
if err != nil || len(runs) != 1 {
|
|
t.Fatalf("lost response duplicated run: %d %v", len(runs), err)
|
|
}
|
|
}
|