@@ -225,6 +225,26 @@ function __c3_send_file($filename)
225
225
return __c3_exit ();
226
226
}
227
227
228
+ /**
229
+ * Keep track of the number of running tests
230
+ * @param bool $decrease default false. Whether to increase or decrease the counter
231
+ */
232
+ function __c3_testcounter ($ decrease = false )
233
+ {
234
+ $ blockfilename = realpath (C3_CODECOVERAGE_MEDIATE_STORAGE ) . DIRECTORY_SEPARATOR . 'block_report ' ;
235
+ $ file = fopen ($ blockfilename , 'c+ ' );
236
+ if (flock ($ file , LOCK_EX )){
237
+ // 24 bytes is enough to hold largest integer supported in 64 bit systems
238
+ $ testcounter = intval (fread ($ file , 24 )) + ($ decrease ? -1 : 1 );
239
+ ftruncate ($ file , 0 );
240
+ rewind ($ file );
241
+ fwrite ($ file , $ testcounter );
242
+ } else {
243
+ __c3_error ("Failed to acquire write-lock for $ blockfilename " );
244
+ }
245
+ fclose ($ file );
246
+ }
247
+
228
248
/**
229
249
* @param $filename
230
250
* @param bool $lock Lock the file for writing?
@@ -242,6 +262,13 @@ function __c3_factory($filename, $lock = false)
242
262
__c3_error ("Failed to acquire write-lock for $ filename " );
243
263
}
244
264
} else {
265
+ // wait until serialized coverage data of all tests is written to file
266
+ $ blockfilename = realpath (C3_CODECOVERAGE_MEDIATE_STORAGE ) . DIRECTORY_SEPARATOR . 'block_report ' ;
267
+ if (file_exists ($ blockfilename ) && filesize ($ blockfilename ) !== 0 ) {
268
+ while (file_get_contents ($ blockfilename ) !== '0 ' ) {
269
+ usleep (250000 ); // 0.25 sec
270
+ }
271
+ }
245
272
$ phpCoverage = unserialize (file_get_contents ($ filename ));
246
273
}
247
274
@@ -383,6 +410,7 @@ function __c3_clear()
383
410
}
384
411
} else {
385
412
list ($ codeCoverage , ) = __c3_factory (null );
413
+ __c3_testcounter ();
386
414
$ codeCoverage ->start (C3_CODECOVERAGE_TESTNAME );
387
415
if (!array_key_exists ('HTTP_X_CODECEPTION_CODECOVERAGE_DEBUG ' , $ _SERVER )) {
388
416
register_shutdown_function (
@@ -419,6 +447,7 @@ function () use ($codeCoverage, $currentReport) {
419
447
flock ($ file , LOCK_UN );
420
448
fclose ($ file );
421
449
}
450
+ __c3_testcounter (true );
422
451
}
423
452
);
424
453
}
0 commit comments