Skip to content

Commit ef26d7d

Browse files
authored
Retry fix (#1070)
* started fixing retries * Fixed UnhadnledException for retries in recorder * reverted some recorder changes * fixed linting
1 parent 2e27a1e commit ef26d7d

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

examples/github_test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ Before((Smth) => {
55
Smth.openGitHub();
66
});
77

8+
Scenario('Visit Home Page @retry', (I) => {
9+
// .retry({ retries: 3, minTimeout: 1000 })
10+
I.retry(2).see('GitHub');
11+
I.retry(3).see('ALL');
12+
I.retry(2).see('IMAGES');
13+
});
14+
815
Scenario('search @grop', (I) => {
916
I.amOnPage('https://github.com/search');
1017
I.fillField('Search GitHub', 'CodeceptJS');

lib/recorder.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ const defaultRetryOptions = {
1818
maxTimeout: 10000,
1919
};
2020

21-
2221
/**
2322
* Singleton object to record all test steps as promises and run them in chain.
2423
*/
2524
module.exports = {
2625

26+
/**
27+
* @var retries Array[object]
28+
*/
2729
retries: [],
2830

2931
/**
@@ -123,6 +125,7 @@ module.exports = {
123125
tasks.push(taskName);
124126
// log(`${currentQueue()}Queued | ${taskName}`);
125127

128+
126129
return promise = Promise.resolve(promise).then((res) => {
127130
const retryOpts = this.retries.slice(-1).pop();
128131
// no retries or unnamed tasks
@@ -132,9 +135,11 @@ module.exports = {
132135

133136
return promiseRetry(Object.assign(defaultRetryOptions, retryOpts), (retry, number) => {
134137
if (number > 1) log(`${currentQueue()}Retrying... Attempt #${number}`);
138+
139+
const retryRules = this.retries.reverse();
140+
135141
return Promise.resolve(res).then(fn).catch((err) => {
136-
// does retry handled or should be thrown
137-
for (const retryObj in this.retries.reverse()) {
142+
for (const retryObj of retryRules) {
138143
if (!retryObj.when) return retry(err);
139144
if (retryObj.when && retryObj.when(err)) return retry(err);
140145
}
@@ -153,7 +158,7 @@ module.exports = {
153158
if (Number.isInteger(opts)) {
154159
opts = { retries: opts };
155160
}
156-
return promise.then(() => this.retries.push(opts));
161+
return this.add(() => this.retries.push(opts));
157162
},
158163

159164
catch(customErrFn) {

0 commit comments

Comments
 (0)