From e10eee523467ef2aa75a8bbdf290c2f5c505fbdc Mon Sep 17 00:00:00 2001 From: chen21019 Date: Mon, 9 Nov 2026 08:30:21 +0800 Subject: [PATCH] fix: preserve Stack completion while child services transition --- .github/workflows/security-release-gate.yml | 6 +- COMPATIBILITY.md | 16 +++ README.md | 6 + docs/releases/compose-executor-0.14.45.md | 28 +++++ executor/handlers/common.go | 13 --- executor/handlers/create_handler.go | 1 - executor/handlers/service_wait.go | 75 ++++++++++++ executor/handlers/service_wait_test.go | 96 +++++++++++++++ executor/handlers/stack_transition_test.go | 123 ++++++++++++++++++++ executor/handlers/upgrade_handler.go | 41 ++----- executor/main.go | 8 +- internal/events/worker_test.go | 59 ++++++++++ 12 files changed, 422 insertions(+), 50 deletions(-) create mode 100644 docs/releases/compose-executor-0.14.45.md create mode 100644 executor/handlers/service_wait.go create mode 100644 executor/handlers/service_wait_test.go create mode 100644 executor/handlers/stack_transition_test.go create mode 100644 internal/events/worker_test.go diff --git a/.github/workflows/security-release-gate.yml b/.github/workflows/security-release-gate.yml index 909a017c..d76afa92 100644 --- a/.github/workflows/security-release-gate.yml +++ b/.github/workflows/security-release-gate.yml @@ -21,7 +21,7 @@ jobs: env: DAPPER_IMAGE: pasturestack/compose-cli-dapper:${{ github.sha }} TRIVY_IMAGE: aquasec/trivy:0.74.0@sha256:62b1e65e8869bc4b4c6aa4fa2b21595256c7c2f6018a9d9ad61caf87187c1969 - VERSION_OVERRIDE: 0.14.44 + VERSION_OVERRIDE: 0.14.45 PLATFORM_COMPAT_JAR_URL: https://api.github.com/repos/PastureStack/orchestration-engine/releases/assets/503322721 PLATFORM_COMPAT_JAR_SHA256: da2a8a51562ed16e296f7e29e99482bb44042ff0834cca679bbe01d951ba1682 @@ -71,7 +71,7 @@ jobs: } run_ci - artifact="dist/artifacts/compose-executor-0.14.44-linux-amd64.gz" + artifact="dist/artifacts/compose-executor-0.14.45-linux-amd64.gz" test -s "$artifact" cp "$artifact" /tmp/compose-executor-first.gz @@ -83,7 +83,7 @@ jobs: mkdir -p evidence/product gzip -cd "$artifact" > evidence/product/compose-executor chmod +x evidence/product/compose-executor - evidence/product/compose-executor --version | grep -F '0.14.44' >/dev/null + evidence/product/compose-executor --version | grep -F '0.14.45' >/dev/null cp "$artifact" evidence/ ( cd evidence diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 5febb5e6..66b6d006 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -1,5 +1,21 @@ # Compatibility Contract +## 0.14.45 source: bounded Stack transition observation + +Stack rollback and finish-upgrade observe each transitioning child for at most +five minutes, polling every 500 ms and publishing original-event progress at +most every ten seconds while pending. These replies use the existing Engine +keepalive protocol; they do not complete the Stack or repeat a child action. +Active children are untouched. Canceled/upgraded rollback and upgraded finish +retain their native owners, configuration and reply contract. + +The event worker is the single terminal-error owner. Timeouts, child errors, +reload failures and progress-publish failures propagate instead of disappearing +inside the old WithTimeout wrapper. Deterministic-clock and real HTTP-client +tests cover delayed settling, exactly-once dispatch, keepalive, deadline and +error propagation. Current source tests and normal release qualification do +not establish matching Server native acceptance. + ## 0.14.44: cancelled Stack service rollback The native Compose Stack rollback handler recognizes `canceled-upgrade` instead diff --git a/README.md b/README.md index 760812b8..de0f1e06 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,12 @@ PastureStack is an independent community effort to preserve, audit, and moderniz ## Project status +The next source candidate, 0.14.45, replaces the three-second child-service +wait with bounded observation and progress replies for Stack rollback and +finish-upgrade. The event worker owns terminal errors; handler failures are +no longer swallowed. Each child action is dispatched once. Current published +artifacts remain 0.14.44 until the normal release checks complete. + The maintained source uses Ubuntu 26.04, Go 1.27.3, and Python 3.14.9 for integration-source verification. Ubuntu build packages, the base image, and Go archives are fixed by snapshot, exact version, and SHA-256. Go dependencies are managed by `go.mod` and a reproducible module vendor tree. AWS access uses AWS SDK for Go v2; container structures use the maintained Moby API module; the command parser uses urfave/cli v3. The abandoned AWS SDK v1, Rancher generated-client modules, event-subscriber module, `docker/libcompose`, and other GOPATH-era dependencies have been removed. The small Rancher 1.6 protocol boundary retained by this compatibility CLI is maintained and tested locally. The Dapper builder does not embed a Docker CLI or mount a Docker socket; Docker is required only on the host to create and run the isolated builder. The maintained binaries are `pasturestack-compose` and `compose-executor`; `platform-compose.yml` is the preferred companion file. Releases are built and verified from the preserved source history; this repository does not enable automated deployment. The current published [v0.14.44](https://github.com/PastureStack/compose-cli/releases/tag/v0.14.44) diff --git a/docs/releases/compose-executor-0.14.45.md b/docs/releases/compose-executor-0.14.45.md new file mode 100644 index 00000000..f12b88c3 --- /dev/null +++ b/docs/releases/compose-executor-0.14.45.md @@ -0,0 +1,28 @@ +# Compose Executor v0.14.45 + +Stack rollback and finish-upgrade no longer abandon a transitioning service +after six half-second polls. Each child is observed for up to five minutes. +While waiting, progress replies keep the original Engine event alive through +its existing keepalive contract. The executor does not repeat the Stack +handler or reissue an already dispatched child action. + +The old WithTimeout adapter swallowed every handler error. Handlers now return +their original errors to the event worker, which alone publishes the terminal +error reply. Timeout, reload, child-transition and progress-publish failures +remain failures rather than a missing completion response. Active children, +previous Stack environment restoration and native service actions are preserved. + +Deterministic-clock regressions cover children settling beyond both the old +three-second limit and the Engine's ordinary event timeout, periodic original- +event keepalive, exactly-once rollback/finish dispatch, active-child isolation, +the bounded deadline and failure propagation. No wall-clock sleep determines +test success. Existing Catalog delegation and control-channel tests remain in +the affected-package checks. The toolchain, dependency graph and security gates +are unchanged; normal release qualification still requires reproducible builds, +race tests, native compatibility, full security evidence and CodeQL. + +Matching Server runtime acceptance is separate from component qualification. +A successful Stack reply alone does not prove workload readiness or data +preservation. Keep the previous qualified Server image for rollback. Restoring +0.14.44 also restores its short-wait/error-suppression limitation; do not delete +workload data, volumes or an unresolved operation to recover it. diff --git a/executor/handlers/common.go b/executor/handlers/common.go index 34ad2b3c..e550bd8f 100644 --- a/executor/handlers/common.go +++ b/executor/handlers/common.go @@ -2,11 +2,9 @@ package handlers import ( "errors" - "fmt" "github.com/PastureStack/compose-cli/internal/events" "github.com/PastureStack/compose-cli/internal/rancherclient/v2" - "github.com/sirupsen/logrus" ) var ( @@ -48,14 +46,3 @@ func reply(event *events.Event, apiClient *client.RancherClient, data map[string reply.Data = data return publishReply(reply, apiClient) } - -func WithTimeout(f func(event *events.Event, apiClient *client.RancherClient) error) func(event *events.Event, apiClient *client.RancherClient) error { - return func(event *events.Event, apiClient *client.RancherClient) error { - err := f(event, apiClient) - if err == ErrTimeout { - logrus.Infof("Timeout processing %s", fmt.Sprintf("%s:%s", event.ResourceType, event.ResourceID)) - return nil - } - return nil - } -} diff --git a/executor/handlers/create_handler.go b/executor/handlers/create_handler.go index aa2e53fa..a780c35b 100644 --- a/executor/handlers/create_handler.go +++ b/executor/handlers/create_handler.go @@ -25,7 +25,6 @@ func CreateStack(event *events.Event, apiClient *client.RancherClient) error { err = errors.New("CatalogLaunchDispatchFailed") } logger.Errorf("Stack Create Event Failed: %s", logging.SafeLogValue(err)) - publishTransitioningReply(err.Error(), event, apiClient, true) return err } diff --git a/executor/handlers/service_wait.go b/executor/handlers/service_wait.go new file mode 100644 index 00000000..ce95fcf8 --- /dev/null +++ b/executor/handlers/service_wait.go @@ -0,0 +1,75 @@ +package handlers + +import ( + "fmt" + "time" + + "github.com/PastureStack/compose-cli/internal/events" + client "github.com/PastureStack/compose-cli/internal/rancherclient/v2" +) + +const ( + serviceWaitTimeout = 5 * time.Minute + servicePollInterval = 500 * time.Millisecond + serviceProgressInterval = 10 * time.Second +) + +// Only observe the child after dispatch. Replaying the Stack handler while a +// child is transitioning could repeat a native mutation. Progress replies keep +// the original Engine event alive; its terminal reply stays with the handler. +type serviceWaiter struct { + reload func(*client.Service) error + progress func() error + now func() time.Time + sleep func(time.Duration) +} + +func newServiceWaiter(event *events.Event, apiClient *client.RancherClient) serviceWaiter { + return serviceWaiter{ + reload: func(service *client.Service) error { + return apiClient.Reload(&service.Resource, service) + }, + progress: func() error { + reply := newReply(event) + reply.Transitioning = "yes" + reply.TransitioningMessage = "Waiting for Stack services" + return publishReply(reply, apiClient) + }, + now: time.Now, + sleep: time.Sleep, + } +} + +func (w serviceWaiter) wait(service *client.Service) error { + deadline := w.now().Add(serviceWaitTimeout) + nextProgress := w.now() + for { + if err := w.reload(service); err != nil { + return err + } + switch service.Transitioning { + case "no": + return nil + case "yes": + // Continue observing below without repeating an action. + default: + return fmt.Errorf("Waiting for %s failed: %s", service.Name, service.TransitioningMessage) + } + + now := w.now() + if !now.Before(deadline) { + return fmt.Errorf("%w: %s", ErrTimeout, service.Name) + } + if !now.Before(nextProgress) { + if err := w.progress(); err != nil { + return err + } + nextProgress = now.Add(serviceProgressInterval) + } + delay := servicePollInterval + if remaining := deadline.Sub(now); remaining < delay { + delay = remaining + } + w.sleep(delay) + } +} diff --git a/executor/handlers/service_wait_test.go b/executor/handlers/service_wait_test.go new file mode 100644 index 00000000..2ecc2121 --- /dev/null +++ b/executor/handlers/service_wait_test.go @@ -0,0 +1,96 @@ +package handlers + +import ( + "errors" + "testing" + "time" + + client "github.com/PastureStack/compose-cli/internal/rancherclient/v2" +) + +func TestServiceWaiterUsesBoundedObservationAndKeepalive(t *testing.T) { + for _, pendingReads := range []int{0, 8, 100} { + t.Run(time.Duration(pendingReads).String(), func(t *testing.T) { + now := time.Unix(0, 0) + reads, progress, pauses := 0, 0, 0 + waiter := serviceWaiter{ + now: func() time.Time { return now }, + sleep: func(delay time.Duration) { + if delay != servicePollInterval { + t.Fatalf("unexpected observation interval: %s", delay) + } + now = now.Add(delay) + pauses++ + }, + reload: func(s *client.Service) error { + reads++ + s.Transitioning = "yes" + if reads > pendingReads { + s.Transitioning = "no" + } + return nil + }, + progress: func() error { progress++; return nil }, + } + if err := waiter.wait(&client.Service{}); err != nil { + t.Fatal(err) + } + wantProgress := 0 + if pendingReads > 0 { + wantProgress = (pendingReads-1)/20 + 1 + } + if reads != pendingReads+1 || pauses != pendingReads || progress != wantProgress { + t.Fatalf("reads/pauses/progress = %d/%d/%d", reads, pauses, progress) + } + }) + } +} + +func TestServiceWaiterReportsDeadlineAndErrors(t *testing.T) { + for _, failure := range []string{"deadline", "reload", "progress", "child"} { + t.Run(failure, func(t *testing.T) { + now := time.Unix(0, 0) + reads, progress, pauses := 0, 0, 0 + original := errors.New("original failure") + waiter := serviceWaiter{ + now: func() time.Time { return now }, + sleep: func(delay time.Duration) { now = now.Add(delay); pauses++ }, + reload: func(s *client.Service) error { + reads++ + s.Transitioning = "yes" + if failure == "reload" { + return original + } + if failure == "child" { + s.Transitioning = "error" + s.TransitioningMessage = "child failed" + } + return nil + }, + progress: func() error { + progress++ + if failure == "progress" { + return original + } + return nil + }, + } + err := waiter.wait(&client.Service{Name: "one-child"}) + if err == nil { + t.Fatal("failure was swallowed") + } + if failure == "deadline" { + if !errors.Is(err, ErrTimeout) || now.Sub(time.Unix(0, 0)) != serviceWaitTimeout || reads != 601 || pauses != 600 || progress != 30 { + t.Fatalf("unbounded or early timeout: %v, reads=%d pauses=%d progress=%d", err, reads, pauses, progress) + } + } else if failure == "reload" || failure == "progress" { + if err != original { + t.Fatalf("original failure replaced: %v", err) + } + } + if failure != "deadline" && pauses != 0 { + t.Fatal("retried a failed operation") + } + }) + } +} diff --git a/executor/handlers/stack_transition_test.go b/executor/handlers/stack_transition_test.go new file mode 100644 index 00000000..ed934fca --- /dev/null +++ b/executor/handlers/stack_transition_test.go @@ -0,0 +1,123 @@ +package handlers + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "strings" + "sync" + "testing" + "time" + + "github.com/PastureStack/compose-cli/internal/events" + client "github.com/PastureStack/compose-cli/internal/rancherclient/v2" +) + +func TestStackTransitionWaitsWithoutReplayingActions(t *testing.T) { + for _, action := range []string{"rollback", "finishupgrade"} { + t.Run(action, func(t *testing.T) { + var server *httptest.Server + var mu sync.Mutex + actions, reads := map[string]int{}, map[string]int{} + terminal, progress := 0, 0 + service := func(id, state, transitioning string) map[string]interface{} { + return map[string]interface{}{ + "id": id, "type": "service", "state": state, "transitioning": transitioning, + "links": map[string]string{"self": server.URL + "/services/" + id}, + "actions": map[string]string{action: server.URL + "/services/" + id + "?action=" + action}, + } + } + server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mu.Lock() + defer mu.Unlock() + w.Header().Set("Content-Type", "application/json") + encode := func(v interface{}) { + if err := json.NewEncoder(w).Encode(v); err != nil { + t.Error(err) + } + } + switch { + case r.URL.Path == "/schemas": + w.Header().Set("X-API-Schemas", server.URL+"/schemas") + var schemas []interface{} + for _, kind := range []string{"stack", "service", "publish"} { + schemas = append(schemas, map[string]interface{}{"id": kind, "resourceMethods": []string{"GET"}, "collectionMethods": []string{"POST"}, "links": map[string]string{"collection": server.URL + "/" + kind + "s"}}) + } + encode(map[string]interface{}{"data": schemas}) + case r.URL.Path == "/stacks/1st7": + encode(map[string]interface{}{"id": "1st7", "previousExternalId": "before", "links": map[string]string{"services": server.URL + "/stacks/1st7/services"}}) + case r.URL.Path == "/stacks/1st7/services": + encode(map[string]interface{}{"data": []interface{}{service("1s1", "upgrading", "yes"), service("1s2", "active", "no"), service("1s3", "upgraded", "no")}}) + case strings.HasPrefix(r.URL.Path, "/services/"): + id := strings.TrimPrefix(r.URL.Path, "/services/") + if r.Method == http.MethodPost { + actions[id]++ + if id == "1s2" || actions[id] != 1 || r.URL.Query().Get("action") != action { + t.Error("replayed or wrong child mutation") + } + reads[id] = 0 + encode(service(id, "transitioning", "yes")) + return + } + reads[id]++ + if id == "1s1" && actions[id] == 0 && reads[id] <= 8 { + encode(service(id, "upgrading", "yes")) + } else if id == "1s1" && actions[id] == 1 && reads[id] <= 100 { + encode(service(id, "transitioning", "yes")) + } else if actions[id] > 0 || id == "1s2" { + encode(service(id, "active", "no")) + } else { + state := "upgraded" + if id == "1s3" && action == "rollback" { + state = "canceled-upgrade" + } + encode(service(id, state, "no")) + } + case r.URL.Path == "/publishs" && r.Method == http.MethodPost: + var reply client.Publish + if err := json.NewDecoder(r.Body).Decode(&reply); err != nil { + t.Error(err) + } + if reply.Name != "reply.original" || len(reply.PreviousIds) != 1 || reply.PreviousIds[0] != "original-event" { + t.Error("lost original event ownership") + } + if reply.Transitioning == "yes" { + progress++ + } else { + terminal++ + if reads["1s1"] != 101 || actions["1s1"] != 1 || actions["1s3"] != 1 { + t.Error("premature terminal reply") + } + } + encode(map[string]interface{}{}) + default: + t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path) + http.NotFound(w, r) + } + })) + defer server.Close() + c, err := client.NewRancherClient(&client.ClientOpts{Url: server.URL + "/schemas"}) + if err != nil { + t.Fatal(err) + } + event := &events.Event{ID: "original-event", ResourceID: "1st7", ReplyTo: "reply.original"} + waiter := newServiceWaiter(event, c) + now := time.Unix(0, 0) + waiter.now = func() time.Time { return now } + waiter.sleep = func(d time.Duration) { now = now.Add(d) } + if action == "rollback" { + err = rollbackStack(event, c, waiter.wait) + } else { + err = finishUpgradeStack(event, c, waiter.wait) + } + if err != nil { + t.Fatal(err) + } + mu.Lock() + defer mu.Unlock() + if terminal != 1 || progress != 6 || actions["1s2"] != 0 { + t.Fatalf("terminal=%d progress=%d actions=%v", terminal, progress, actions) + } + }) + } +} diff --git a/executor/handlers/upgrade_handler.go b/executor/handlers/upgrade_handler.go index e47d94bd..424476f1 100644 --- a/executor/handlers/upgrade_handler.go +++ b/executor/handlers/upgrade_handler.go @@ -2,8 +2,6 @@ package handlers import ( "errors" - "fmt" - "time" "context" @@ -25,7 +23,6 @@ func UpgradeStack(event *events.Event, apiClient *client.RancherClient) error { if err := upgradeEnvironment(logger, event, apiClient); err != nil { logger.Errorf("Stack Upgrade Event Failed: %s", logging.SafeLogValue(err)) - publishTransitioningReply(err.Error(), event, apiClient, false) return err } @@ -34,6 +31,10 @@ func UpgradeStack(event *events.Event, apiClient *client.RancherClient) error { } func FinishUpgradeStack(event *events.Event, apiClient *client.RancherClient) error { + return finishUpgradeStack(event, apiClient, newServiceWaiter(event, apiClient).wait) +} + +func finishUpgradeStack(event *events.Event, apiClient *client.RancherClient, wait func(*client.Service) error) error { logger := logrus.WithFields(logrus.Fields{ "resourceId": logging.SafeLogValue(event.ResourceID), "eventId": logging.SafeLogValue(event.ID), @@ -56,7 +57,7 @@ func FinishUpgradeStack(event *events.Event, apiClient *client.RancherClient) er } for _, service := range services.Data { - if err := wait(apiClient, &service); err != nil { + if err := wait(&service); err != nil { return err } if service.State == "upgraded" { @@ -64,7 +65,7 @@ func FinishUpgradeStack(event *events.Event, apiClient *client.RancherClient) er if err != nil { return err } - if err := wait(apiClient, service); err != nil { + if err := wait(service); err != nil { return err } } @@ -78,6 +79,10 @@ func FinishUpgradeStack(event *events.Event, apiClient *client.RancherClient) er } func RollbackStack(event *events.Event, apiClient *client.RancherClient) error { + return rollbackStack(event, apiClient, newServiceWaiter(event, apiClient).wait) +} + +func rollbackStack(event *events.Event, apiClient *client.RancherClient, wait func(*client.Service) error) error { logger := logrus.WithFields(logrus.Fields{ "resourceId": logging.SafeLogValue(event.ResourceID), "eventId": logging.SafeLogValue(event.ID), @@ -100,7 +105,7 @@ func RollbackStack(event *events.Event, apiClient *client.RancherClient) error { } for _, service := range services.Data { - if err := wait(apiClient, &service); err != nil { + if err := wait(&service); err != nil { return err } if service.State == "upgraded" || service.State == "canceled-upgrade" { @@ -108,7 +113,7 @@ func RollbackStack(event *events.Event, apiClient *client.RancherClient) error { if err != nil { return err } - if err := wait(apiClient, service); err != nil { + if err := wait(service); err != nil { return err } } @@ -132,28 +137,6 @@ func RollbackStack(event *events.Event, apiClient *client.RancherClient) error { }) } -func wait(apiClient *client.RancherClient, service *client.Service) error { - for i := 0; i < 6; i++ { - if err := apiClient.Reload(&service.Resource, service); err != nil { - return err - } - if service.Transitioning != "yes" { - break - } - time.Sleep(500 * time.Millisecond) - } - - switch service.Transitioning { - case "yes": - logrus.Infof("Timeout waiting for %s to finish", logging.SafeLogValue(service.Name)) - return ErrTimeout - case "no": - return nil - default: - return fmt.Errorf("Waiting for %s failed: %s", service.Name, service.TransitioningMessage) - } -} - func upgradeEnvironment(logger *logrus.Entry, event *events.Event, apiClient *client.RancherClient) error { var upgradeOpts client.StackUpgrade diff --git a/executor/main.go b/executor/main.go index e708d67d..da149e1e 100644 --- a/executor/main.go +++ b/executor/main.go @@ -26,10 +26,10 @@ func Main() { logger.Info(executorMessage(locale, "start")) eventHandlers := map[string]events.EventHandler{ - "stack.create": handlers.WithTimeout(handlers.CreateStack), - "stack.upgrade": handlers.WithTimeout(handlers.UpgradeStack), - "stack.finishupgrade": handlers.WithTimeout(handlers.FinishUpgradeStack), - "stack.rollback": handlers.WithTimeout(handlers.RollbackStack), + "stack.create": handlers.CreateStack, + "stack.upgrade": handlers.UpgradeStack, + "stack.finishupgrade": handlers.FinishUpgradeStack, + "stack.rollback": handlers.RollbackStack, "ping": func(event *events.Event, apiClient *client.RancherClient) error { return nil }, diff --git a/internal/events/worker_test.go b/internal/events/worker_test.go new file mode 100644 index 00000000..3eb2f21d --- /dev/null +++ b/internal/events/worker_test.go @@ -0,0 +1,59 @@ +package events + +import ( + "encoding/json" + "errors" + "net/http" + "net/http/httptest" + "sync" + "testing" + + "github.com/PastureStack/compose-cli/internal/locks" + client "github.com/PastureStack/compose-cli/internal/rancherclient/v2" +) + +func TestWorkerPublishesOneOriginalTerminalError(t *testing.T) { + for _, message := range []string{"Timeout waiting service", "reload failed", "publish failed"} { + t.Run(message, func(t *testing.T) { + calls, replies := 0, 0 + var server *httptest.Server + var mu sync.Mutex + server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mu.Lock() + defer mu.Unlock() + w.Header().Set("Content-Type", "application/json") + if r.URL.Path == "/schemas" { + w.Header().Set("X-API-Schemas", server.URL+"/schemas") + _ = json.NewEncoder(w).Encode(map[string]interface{}{"data": []interface{}{map[string]interface{}{"id": "publish", "collectionMethods": []string{"POST"}, "links": map[string]string{"collection": server.URL + "/publish"}}}}) + return + } + if r.Method != http.MethodPost || r.URL.Path != "/publish" { + t.Error("unexpected request") + http.NotFound(w, r) + return + } + replies++ + var reply client.Publish + if err := json.NewDecoder(r.Body).Decode(&reply); err != nil { + t.Error(err) + } + if reply.Name != "reply.original" || len(reply.PreviousIds) != 1 || reply.PreviousIds[0] != "original" || reply.Transitioning != "error" || reply.TransitioningMessage != message { + t.Errorf("wrong terminal reply: %#v", reply) + } + _ = json.NewEncoder(w).Encode(map[string]interface{}{}) + })) + defer server.Close() + c, err := client.NewRancherClient(&client.ClientOpts{Url: server.URL + "/schemas"}) + if err != nil { + t.Fatal(err) + } + event := &Event{ID: "original", Name: "stack.rollback", ReplyTo: "reply.original"} + doWork(event, map[string]EventHandler{"stack.rollback": func(*Event, *client.RancherClient) error { calls++; return errors.New(message) }}, c, locks.NopLocker()) + mu.Lock() + defer mu.Unlock() + if calls != 1 || replies != 1 { + t.Fatalf("calls=%d replies=%d", calls, replies) + } + }) + } +}