summaryrefslogtreecommitdiff
path: root/dist
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2011-04-15 10:17:07 +0100
committerDavid Mitchell <davem@iabyn.com>2011-04-15 10:23:43 +0100
commitbb09c94c3bb1638714998511ecf5d337a708535a (patch)
tree52dba2d0454f4997512d9ad2939bf8d681fea35c /dist
parentb4ffc3db31e268adb50c44bab9b628dc619f1e83 (diff)
downloadperl-bb09c94c3bb1638714998511ecf5d337a708535a.tar.gz
stop waithires.t failing under high load
In threads::shared, the waithires.t test checks cond_timedwait() with sub-second timeouts. If the newly-minted child doesn't manage to grab the lock within 0.05s, the cond_timedwait() will timeout, and the child and the test will hang, until eventually killed off by the watchdog. This can easily happen on a slow/loaded system. We fix this by putting the cond_timedwait() in a retry loop, only giving up after 10 seconds of repeated timeouts.
Diffstat (limited to 'dist')
-rw-r--r--dist/threads-shared/t/waithires.t30
1 files changed, 24 insertions, 6 deletions
diff --git a/dist/threads-shared/t/waithires.t b/dist/threads-shared/t/waithires.t
index e3a1086370..3c3e85263f 100644
--- a/dist/threads-shared/t/waithires.t
+++ b/dist/threads-shared/t/waithires.t
@@ -70,6 +70,24 @@ my @wait_how = (
"twain" # cond var != lock var; explicit lock; e.g.: cond_wait($c, $l)
);
+# run cond_timedwait, and repeat if it times out (give up after 10 secs)
+
+sub cond_timedwaitN {
+ my $ok;
+ my $end = time() + 10;
+ while (1) {
+ if (@_ == 3) {
+ $ok = cond_timedwait($_[0], $_[1], $_[2]);
+ }
+ else {
+ $ok = cond_timedwait($_[0], $_[1]);
+ }
+ last if $ok;
+ last if time() > $end;
+ }
+ return $ok;
+}
+
SYNC_SHARED: {
my $test_type :shared; # simple|repeat|twain
@@ -111,9 +129,9 @@ SYNC_SHARED: {
my $thr = threads->create(\&signaller, $testnum);
my $ok = 0;
for ($test_type) {
- $ok = cond_timedwait($cond, time() + $to), last if /simple/;
- $ok = cond_timedwait($cond, time() + $to, $cond), last if /repeat/;
- $ok = cond_timedwait($cond, time() + $to, $lock), last if /twain/;
+ $ok = cond_timedwaitN($cond, time() + $to), last if /simple/;
+ $ok = cond_timedwaitN($cond, time() + $to, $cond), last if /repeat/;
+ $ok = cond_timedwaitN($cond, time() + $to, $lock), last if /twain/;
die "$test_type: unknown test\n";
}
$testnum = $thr->join();
@@ -215,9 +233,9 @@ SYNCH_REFS: {
my $thr = threads->create(\&signaller2, $testnum);
my $ok = 0;
for ($test_type) {
- $ok = cond_timedwait($cond, time() + $to), last if /simple/;
- $ok = cond_timedwait($cond, time() + $to, $cond), last if /repeat/;
- $ok = cond_timedwait($cond, time() + $to, $lock), last if /twain/;
+ $ok = cond_timedwaitN($cond, time() + $to), last if /simple/;
+ $ok = cond_timedwaitN($cond, time() + $to, $cond), last if /repeat/;
+ $ok = cond_timedwaitN($cond, time() + $to, $lock), last if /twain/;
die "$test_type: unknown test\n";
}
$testnum = $thr->join();