9
9
use Codeception \Exception \ModuleRequireException ;
10
10
use Codeception \Module \WebDriver ;
11
11
use Codeception \Step ;
12
- use Codeception \TestInterface ;
13
12
use Facebook \WebDriver \Exception \UnexpectedAlertOpenException ;
14
13
use Magento \FunctionalTestingFramework \Extension \PageReadinessExtension ;
15
14
use Magento \FunctionalTestingFramework \Util \Logger \LoggingUtil ;
@@ -29,18 +28,26 @@ abstract class AbstractMetricCheck
29
28
protected $ extension ;
30
29
31
30
/**
32
- * The active test object
31
+ * Current state of the value the metric tracks
33
32
*
34
- * @var TestInterface
33
+ * @var mixed;
35
34
*/
36
- protected $ test ;
35
+ protected $ currentValue ;
37
36
38
37
/**
39
- * Current state of the value the metric tracks
38
+ * Most recent saved state of the value the metric tracks
39
+ * Updated when the metric passes or is finalized
40
40
*
41
41
* @var mixed;
42
42
*/
43
- protected $ currentValue ;
43
+ protected $ storedValue ;
44
+
45
+ /**
46
+ * Current count of sequential identical failures
47
+ *
48
+ * @var integer;
49
+ */
50
+ protected $ failCount ;
44
51
45
52
/**
46
53
* Number of sequential identical failures before force-resetting the metric
@@ -63,14 +70,12 @@ abstract class AbstractMetricCheck
63
70
* Constructor, called from the beforeTest event
64
71
*
65
72
* @param PageReadinessExtension $extension
66
- * @param TestInterface $test
67
73
* @param integer $resetFailureThreshold
68
74
* @throws \Exception
69
75
*/
70
- public function __construct ($ extension , $ test , $ resetFailureThreshold )
76
+ public function __construct ($ extension , $ resetFailureThreshold )
71
77
{
72
78
$ this ->extension = $ extension ;
73
- $ this ->test = $ test ;
74
79
$ this ->logger = LoggingUtil::getInstance ()->getLogger (get_class ($ this ));
75
80
$ this ->verbose = MftfApplicationConfig::getConfig ()->verboseEnabled ();
76
81
@@ -83,7 +88,7 @@ public function __construct($extension, $test, $resetFailureThreshold)
83
88
$ this ->resetFailureThreshold = -1 ;
84
89
}
85
90
86
- $ this ->setTracker ();
91
+ $ this ->resetTracker ();
87
92
}
88
93
89
94
/**
@@ -141,7 +146,7 @@ public function getName()
141
146
public function runCheck ()
142
147
{
143
148
if ($ this ->doesMetricPass ($ this ->getCurrentValue (true ))) {
144
- $ this ->setTracker ($ this ->getCurrentValue ());
149
+ $ this ->setTracker ($ this ->getCurrentValue (), 0 );
145
150
return true ;
146
151
}
147
152
@@ -157,35 +162,35 @@ public function runCheck()
157
162
* @param Step $step
158
163
* @return void
159
164
*/
160
- public function finalize ($ step )
165
+ public function finalizeForStep ($ step )
161
166
{
162
167
try {
163
168
$ currentValue = $ this ->getCurrentValue ();
164
169
} catch (UnexpectedAlertOpenException $ exception ) {
165
170
$ this ->debugLog (
166
171
'An alert is open, bypassing javascript-based metric check ' ,
167
- ['action ' => $ step ->getAction ()]
172
+ ['step ' => $ step ->__toString ()]
168
173
);
169
174
return ;
170
175
}
171
176
172
177
if ($ this ->doesMetricPass ($ currentValue )) {
173
- $ this ->setTracker ($ currentValue );
178
+ $ this ->setTracker ($ currentValue, 0 );
174
179
} else {
175
180
// If failure happened on the same value as before, increment the fail count, otherwise set at 1
176
- if ($ currentValue !== $ this ->getStoredValue ()) {
181
+ if (! isset ( $ this -> storedValue ) || $ currentValue !== $ this ->getStoredValue ()) {
177
182
$ failCount = 1 ;
178
183
} else {
179
184
$ failCount = $ this ->getFailureCount () + 1 ;
180
185
}
181
186
$ this ->setTracker ($ currentValue , $ failCount );
182
187
183
- $ this ->errorLog ('Failed readiness check ' , ['action ' => $ step ->getAction ()]);
188
+ $ this ->errorLog ('Failed readiness check ' , ['step ' => $ step ->__toString ()]);
184
189
185
190
if ($ this ->resetFailureThreshold >= 0 && $ failCount >= $ this ->resetFailureThreshold ) {
186
191
$ this ->debugLog (
187
192
'Too many failures, assuming metric is stuck and resetting state ' ,
188
- ['action ' => $ step ->getAction ()]
193
+ ['step ' => $ step ->__toString ()]
189
194
);
190
195
$ this ->resetMetric ();
191
196
}
@@ -214,7 +219,7 @@ protected function getDriver()
214
219
*/
215
220
protected function executeJs ($ script , $ arguments = [])
216
221
{
217
- return $ this ->getDriver ()->executeJS ($ script , $ arguments );
222
+ return $ this ->extension -> getDriver ()->executeJS ($ script , $ arguments );
218
223
}
219
224
220
225
/**
@@ -243,7 +248,7 @@ private function getCurrentValue($refresh = false)
243
248
*/
244
249
public function getStoredValue ()
245
250
{
246
- return $ this ->test -> getMetadata ()-> getCurrent ( $ this -> getName ()) ;
251
+ return $ this ->storedValue ;
247
252
}
248
253
249
254
/**
@@ -254,7 +259,7 @@ public function getStoredValue()
254
259
*/
255
260
public function getFailureCount ()
256
261
{
257
- return $ this ->test -> getMetadata ()-> getCurrent ( $ this -> getName () . ' . failCount' ) ;
262
+ return $ this ->failCount ;
258
263
}
259
264
260
265
/**
@@ -266,7 +271,7 @@ public function getFailureCount()
266
271
private function resetMetric ()
267
272
{
268
273
$ this ->clearFailureOnPage ();
269
- $ this ->setTracker ();
274
+ $ this ->resetTracker ();
270
275
}
271
276
272
277
/**
@@ -276,13 +281,18 @@ private function resetMetric()
276
281
* @param integer $failCount
277
282
* @return void
278
283
*/
279
- public function setTracker ($ value = null , $ failCount = 0 )
284
+ public function setTracker ($ value , $ failCount )
285
+ {
286
+ unset($ this ->currentValue );
287
+ $ this ->storedValue = $ value ;
288
+ $ this ->failCount = $ failCount ;
289
+ }
290
+
291
+ public function resetTracker ()
280
292
{
281
- $ this ->test ->getMetadata ()->setCurrent ([
282
- $ this ->getName () => $ value ,
283
- $ this ->getName () . '.failCount ' => $ failCount
284
- ]);
285
293
unset($ this ->currentValue );
294
+ unset($ this ->storedValue );
295
+ $ this ->failCount = 0 ;
286
296
}
287
297
288
298
/**
@@ -334,10 +344,9 @@ protected function debugLog($message, $context = [])
334
344
*/
335
345
private function getLogContext ()
336
346
{
337
- $ testMeta = $ this ->test ->getMetadata ();
338
347
return [
339
- 'test ' => $ testMeta -> getName (),
340
- 'uri ' => $ testMeta -> getCurrent ( ' uri ' ),
348
+ 'test ' => $ this -> extension -> getTestName (),
349
+ 'uri ' => $ this -> extension -> getUri ( ),
341
350
$ this ->getName () => $ this ->getStoredValue (),
342
351
$ this ->getName () . '.failCount ' => $ this ->getFailureCount ()
343
352
];
0 commit comments