Skip to content

Commit

Permalink
maxSuiteDuration (#181)
Browse files Browse the repository at this point in the history
* max suite duration

* scenario b not opened

* docs

* dangle suite should fail

* another example
  • Loading branch information
johnsickels authored Nov 23, 2021
1 parent 68f89ba commit 79af80e
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 2 deletions.
15 changes: 14 additions & 1 deletion docs/suite.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ suite.scenario("User login flow", "appium", {
deviceName: "Name of device",
platformName: "Android" | "iOS",
automationName: "Uiautomator2" | "XCUITest" | "Espresso",
app: "/path/to/apk/or/ipa"
app: "/path/to/apk/or/ipa",
});
```

Expand Down Expand Up @@ -334,6 +334,19 @@ The execution options specified from the command line arguments or defaults. Thi
const baseDomain = suite.executionOptions.environment?.defaultDomain;
```
### maxSuiteDuration: number
How long a suite will run before timing out. The default is 60000 ( one minute )
```javascript
const suite = flagpole("A very long suite");

// this suite can run for two minutes
suite.maxSuiteDuration = 120000;

suite.browser("Interact with the browser for a while");
```
### title: string
The title of this suite, which is specified in the constructor.
Expand Down
10 changes: 10 additions & 0 deletions flagpole-should-fail.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
"id": "",
"name": "timeout",
"tags": []
},
"dangle": {
"id": "",
"name": "dangle",
"tags": []
},
"noNext": {
"id": "",
"name": "noNext",
"tags": []
}
}
}
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ export interface iSuite {
totalDuration: number | null;
executionDuration: number | null;
maxScenarioDuration: number;
maxSuiteDuration: number;
concurrencyLimit: number;
title: string;
finished: Promise<void>;
Expand Down
19 changes: 19 additions & 0 deletions src/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,25 @@ export class Suite implements iSuite {
this._taskManager.maxScenarioDuration = timeoutMs;
}

/**
* If a suite hasn't completed in this period of time, cut the scenarios off
*
* @param timeout
* @returns
*/
public setMaxSuiteDuration(timeout: number): iSuite {
this._taskManager.maxSuiteDuration = timeout;
return this;
}

public get maxSuiteDuration(): number {
return this._taskManager.maxSuiteDuration;
}

public set maxSuiteDuration(timeoutMs: number) {
this._taskManager.maxSuiteDuration = timeoutMs;
}

/**
* Print all logs to console
*
Expand Down
21 changes: 20 additions & 1 deletion src/suitetaskmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SuiteTaskManager {
private _statusCallbacks: SuiteStatusCallback[] = [];
private _concurrencyLimit: number = 99;
private _maxScenarioDuration: number = 30000;
private _maxTimeToWaitForPendingScenariosToBeReady = 30000;
private _maxSuiteDuration: number = 60000;
private _finishedPromise: Promise<void>;
private _finishedResolve = () => {};

Expand All @@ -54,6 +54,14 @@ export class SuiteTaskManager {
this._maxScenarioDuration = value;
}

public get maxSuiteDuration(): number {
return this._maxSuiteDuration;
}

public set maxSuiteDuration(value: number) {
this._maxSuiteDuration = value;
}

public get concurrencyLimit(): number {
return this._concurrencyLimit;
}
Expand Down Expand Up @@ -343,6 +351,17 @@ export class SuiteTaskManager {
// If we have some pending + we didn't start any new ones, kill them
// Important! Don't finish it off right away, there may be something pending in a few milliseconds
runAsync(() => {
if (
this.scenariosWaitingToExecute.length > 0 &&
this._dateExecutionBegan &&
Date.now() - this._dateExecutionBegan > this._maxSuiteDuration
) {
resolve(
this._cancelPendingScenarios(
"Suite timed out! This scenario was never called or had no assertions."
)
);
}
// If there are more scenarios now ready to execute, do those
if (this.scenariosWaitingToExecute.length > 0) {
return execute();
Expand Down
18 changes: 18 additions & 0 deletions tests/src/dangle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import flagpole from "../../dist";

const suite = flagpole("Scenario with no open method");

suite.maxSuiteDuration = 5000;

suite
.scenario("Scenario should timeout", "html")
.open("https://dribbble.com/")
.next((context) => {
context.assert(context.response.statusCode).equals(200);
throw "foo";
scenarioB.open("https://www.dezeen.com/");
});

const scenarioB = suite.scenario("Scenario B", "html").next((context) => {
context.assert(context.response.statusCode).equals(200);
});
7 changes: 7 additions & 0 deletions tests/src/noNext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import flagpole from "../../dist";

const suite = flagpole("No .next will dangle");

suite.maxSuiteDuration = 3000;

suite.html("Homepage Loads").open("https://dribbble.com/");

0 comments on commit 79af80e

Please sign in to comment.