Improve testing code to better diagnose concurrency bugs.
authorRobert Haas <[email protected]>
Fri, 27 Jul 2012 17:49:12 +0000 (17:49 +0000)
committerRobert Haas <[email protected]>
Fri, 27 Jul 2012 17:49:12 +0000 (17:49 +0000)
contrib/hashtest/hashtest.c

index d15c76abafffaf9f547690f7ec0d38485ea245e2..90d525da1dea6c078b6e83e2a6e5ea77e5ce8aef 100644 (file)
@@ -193,8 +193,15 @@ chash_concurrent_test(PG_FUNCTION_ARGS)
                e.val = 0;
                ok = CHashSearch(chash, &e);
                if (!ok)
+               {
+                       uint64  retry = 1;
                        elog(LOG, "search %u: not found", i);
-               else if (e.val != MyProcPid)
+                       while (!CHashSearch(chash, &e))
+                               ++retry;
+                       elog(LOG, "search %u: eventually found it after "
+                               UINT64_FORMAT " retries", i, retry);
+               }
+               if (e.val != MyProcPid)
                        elog(LOG, "search %u: expected %u found %u", i, (unsigned) MyProcPid, e.val);
        }
 
@@ -205,7 +212,14 @@ chash_concurrent_test(PG_FUNCTION_ARGS)
                e.key = seed | i;
                ok = CHashDelete(chash, &e);
                if (!ok)
+               {
+                       uint64  retry = 1;
                        elog(LOG, "delete %u: not found", i);
+                       while (!CHashDelete(chash, &e))
+                               ++retry;
+                       elog(LOG, "delete %u: eventually deleted it after "
+                               UINT64_FORMAT " retries", i, retry);
+               }
        }
 
        PG_RETURN_VOID();