Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow users to stop a running test (#2367)
- Loading branch information
Showing
21 changed files
with
207 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
PORT=$1 | ||
|
||
CONDITION='nc -z -w 1 localhost '$PORT' > /dev/null 2>&1' | ||
IF_TRUE='echo "port '$PORT' ready"' | ||
IF_FALSE='echo "port '$PORT' not available, retry"' | ||
|
||
set -ex | ||
bash -c "until ${CONDITION}; do ${IF_FALSE}; sleep 1; done; ${IF_TRUE}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package executor | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/kubeshop/tracetest/server/id" | ||
"github.com/kubeshop/tracetest/server/model" | ||
"github.com/kubeshop/tracetest/server/model/events" | ||
"github.com/kubeshop/tracetest/server/subscription" | ||
) | ||
|
||
type StopRequest struct { | ||
TestID id.ID | ||
RunID int | ||
} | ||
|
||
func (sr StopRequest) ResourceID() string { | ||
runID := (model.Run{ID: sr.RunID, TestID: sr.TestID}).ResourceID() | ||
return runID + "/stop" | ||
} | ||
|
||
func (r persistentRunner) listenForStopRequests(ctx context.Context, cancelCtx context.CancelFunc, run model.Run) { | ||
sfn := subscription.NewSubscriberFunction(func(m subscription.Message) error { | ||
stopRequest, ok := m.Content.(StopRequest) | ||
if !ok { | ||
return nil | ||
} | ||
|
||
ctx, _ := r.tracer.Start(ctx, "User Requested Stop Run") | ||
// refresh data from DB to make sure we have the latest possible data before updating | ||
run, err := r.runs.GetRun(ctx, stopRequest.TestID, stopRequest.RunID) | ||
if err != nil { | ||
log.Printf("[TracePoller] Test %s Run %d: fail to get test run data: %s \n", stopRequest.TestID, stopRequest.RunID, err.Error()) | ||
return err | ||
} | ||
|
||
run = run.Stopped() | ||
r.handleDBError(run, r.updater.Update(ctx, run)) | ||
|
||
evt := events.TraceStoppedInfo(stopRequest.TestID, stopRequest.RunID) | ||
err = r.eventEmitter.Emit(ctx, evt) | ||
if err != nil { | ||
log.Printf("[TracePoller] Test %s Run %d: fail to emit TraceStoppedInfo event: %s \n", stopRequest.TestID, stopRequest.RunID, err.Error()) | ||
return err | ||
} | ||
|
||
cancelCtx() | ||
|
||
return nil | ||
}) | ||
|
||
r.subscriptionManager.Subscribe((StopRequest{run.TestID, run.ID}).ResourceID(), sfn) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.