mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
refactor(runner): caller manages app launch/terminate
Removes Launch + Terminate from runner.Run so the CLI can launch the app first, wait for the SDK to connect, then start the loop. The previous shape forced runner to launch internally which fought with the SDK-must-be-connected-first ordering. BundleID/ClearState fields go away too since runner no longer launches; the CLI keeps them on its testOptions struct.
This commit is contained in:
1 parent
0c68e72341
commit
e7b3e2ba9c
2 files changed
+4
-19
No files matched your search
@@ -15,8 +15,6 @@ import (
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
BundleID string
|
||||
ClearState bool
|
||||
Duration time.Duration
|
||||
SnapshotTimeout time.Duration
|
||||
IdleTimeout time.Duration
|
||||
@@ -39,20 +37,16 @@ type ViolationRecord struct {
|
||||
Properties []string
|
||||
}
|
||||
|
||||
// Run drives the snapshot/evaluate/release/act loop until the duration
|
||||
// elapses or the context is canceled. The caller is responsible for
|
||||
// launching the app and connecting the SDK before Run is called, and for
|
||||
// terminating the app afterwards.
|
||||
func Run(ctx context.Context, options Options) (Summary, error) {
|
||||
if err := validate(options); err != nil {
|
||||
return Summary{}, err
|
||||
}
|
||||
|
||||
summary := Summary{StartTime: time.Now()}
|
||||
|
||||
if err := options.Driver.Launch(ctx, options.BundleID, options.ClearState); err != nil {
|
||||
return summary, fmt.Errorf("launch: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = options.Driver.Terminate(context.Background())
|
||||
}()
|
||||
|
||||
deadline := summary.StartTime.Add(options.Duration)
|
||||
stepIndex := 0
|
||||
for time.Now().Before(deadline) {
|
||||
|
||||
@@ -129,7 +129,6 @@ func TestRunner_HappyPathStepsAndTraces(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
summary, err := Run(ctx, Options{
|
||||
BundleID: "com.fixture",
|
||||
Duration: 100 * time.Millisecond,
|
||||
SnapshotTimeout: 2 * time.Second,
|
||||
IdleTimeout: 50 * time.Millisecond,
|
||||
@@ -149,15 +148,9 @@ func TestRunner_HappyPathStepsAndTraces(t *testing.T) {
|
||||
}
|
||||
|
||||
actions := state.mock.Actions()
|
||||
if !containsAction(actions, mockdriver.ActionLaunch, "com.fixture") {
|
||||
t.Errorf("expected Launch with com.fixture, got %v", actions)
|
||||
}
|
||||
if !containsAction(actions, mockdriver.ActionTapSelector, "id:next") {
|
||||
t.Errorf("expected TapSelector with id:next, got %v", actions)
|
||||
}
|
||||
if !containsAction(actions, mockdriver.ActionTerminate, "") {
|
||||
t.Errorf("expected Terminate, got %v", actions)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunner_ViolationSurfacesInSummary(t *testing.T) {
|
||||
@@ -173,7 +166,6 @@ func TestRunner_ViolationSurfacesInSummary(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
summary, err := Run(ctx, Options{
|
||||
BundleID: "com.fixture",
|
||||
Duration: 100 * time.Millisecond,
|
||||
SnapshotTimeout: 2 * time.Second,
|
||||
IdleTimeout: 50 * time.Millisecond,
|
||||
@@ -223,7 +215,6 @@ func TestRunner_RecordsScreenFieldFromSnapshot(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if _, err := Run(ctx, Options{
|
||||
BundleID: "com.fixture",
|
||||
Duration: 100 * time.Millisecond,
|
||||
SnapshotTimeout: 2 * time.Second,
|
||||
IdleTimeout: 50 * time.Millisecond,
|
||||
|
||||
Reference in new issue
Block a user