Skip to content

Commit 3d2db84

Browse files
committed
Speed up waiting for file removal
1 parent 3d68bcd commit 3d2db84

1 file changed

Lines changed: 42 additions & 11 deletions

File tree

testsuite/testsuite.c

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ int testsuite_test(int argc, char** argv)
264264
#if !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT) && \
265265
defined(HAVE_CRL) && defined(HAVE_CRL_MONITOR)
266266
#define CRL_MONITOR_TEST_ROUNDS 6
267+
#define CRL_MONITOR_REM_FILE_ATTEMPTS 20
267268

268269
static int test_crl_monitor(void)
269270
{
@@ -291,7 +292,7 @@ static int test_crl_monitor(void)
291292
"-H", "exitWithRet"
292293
};
293294
int ret = -1;
294-
int i;
295+
int i = -1, j;
295296

296297
printf("\nRunning CRL monitor test\n");
297298

@@ -321,44 +322,74 @@ static int test_crl_monitor(void)
321322
if (i % 2 == 0) {
322323
/* succeed on even rounds */
323324
sprintf(buf, "%s/%s", tmpDir, "crl.pem");
324-
copy_file("certs/crl/crl.pem", buf);
325+
if (copy_file("certs/crl/crl.pem", buf) != 0) {
326+
fprintf(stderr, "[%d] Failed to copy file to %s\n", i, buf);
327+
goto cleanup;
328+
}
325329
sprintf(buf, "%s/%s", tmpDir, "crl.revoked");
326330
/* The monitor can be holding the file handle and this will cause
327-
* the remove call to fail. Let's give the monitor a second to
331+
* the remove call to fail. Let's give the monitor a some time to
328332
* finish up. */
329-
XSLEEP_MS(1000);
330-
rem_file(buf);
333+
for (j = 0; j < CRL_MONITOR_REM_FILE_ATTEMPTS; j++) {
334+
/* i == 0 since there is nothing to delete in the first round */
335+
if (i == 0 || rem_file(buf) == 0)
336+
break;
337+
XSLEEP_MS(100);
338+
}
339+
if (j == CRL_MONITOR_REM_FILE_ATTEMPTS) {
340+
fprintf(stderr, "[%d] Failed to remove file %s\n", i, buf);
341+
goto cleanup;
342+
}
331343
expectFail = 0;
332344
}
333345
else {
334346
/* fail on odd rounds */
335347
sprintf(buf, "%s/%s", tmpDir, "crl.revoked");
336-
copy_file("certs/crl/crl.revoked", buf);
348+
if (copy_file("certs/crl/crl.revoked", buf) != 0) {
349+
fprintf(stderr, "[%d] Failed to copy file to %s\n", i, buf);
350+
goto cleanup;
351+
}
337352
sprintf(buf, "%s/%s", tmpDir, "crl.pem");
338353
/* The monitor can be holding the file handle and this will cause
339-
* the remove call to fail. Let's give the monitor a second to
354+
* the remove call to fail. Let's give the monitor a some time to
340355
* finish up. */
341-
XSLEEP_MS(1000);
342-
rem_file(buf);
356+
for (j = 0; j < CRL_MONITOR_REM_FILE_ATTEMPTS; j++) {
357+
if (rem_file(buf) == 0)
358+
break;
359+
XSLEEP_MS(100);
360+
}
361+
if (j == CRL_MONITOR_REM_FILE_ATTEMPTS) {
362+
fprintf(stderr, "[%d] Failed to remove file %s\n", i, buf);
363+
goto cleanup;
364+
}
343365
expectFail = 1;
344366
}
367+
/* Give server a moment to register the file change */
368+
XSLEEP_MS(100);
345369

346370
client_args.return_code = 0;
347371
client_test(&client_args);
348372

349373
if (!expectFail) {
350-
if (client_args.return_code != 0)
374+
if (client_args.return_code != 0) {
375+
fprintf(stderr, "[%d] Incorrect return %d\n", i,
376+
client_args.return_code);
351377
goto cleanup;
378+
}
352379
}
353380
else {
354-
if (client_args.return_code == 0)
381+
if (client_args.return_code == 0) {
382+
fprintf(stderr, "[%d] Expected failure\n", i);
355383
goto cleanup;
384+
}
356385
}
357386
}
358387

359388
join_thread(serverThread);
360389
ret = 0;
361390
cleanup:
391+
if (ret != 0 && i >= 0)
392+
fprintf(stderr, "test_crl_monitor failed on iteration %d\n", i);
362393
sprintf(buf, "%s/%s", tmpDir, "crl.pem");
363394
rem_file(buf);
364395
sprintf(buf, "%s/%s", tmpDir, "crl.revoked");

0 commit comments

Comments
 (0)