perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <>
Subject [mp2] how should we write tests under threads
Date Tue, 19 Apr 2005 23:24:01 GMT
As I've mentioned in another thread perl@24247 adds CLONE_SKIP, so much 
needed by mod_perl. With the patch I've just posted none of the mp2 
objects is cloned when a new thread is started. That means that a thread 
won't be able to use any of the objects created outside of the thread. 
Which is good, but it creates a problem with Apache-Test, which relies on 
the tied STDOUT to run ok()'s. Inside the thread any print on the tied 
STDOUT will fail, since it's tied to an invalid object. We can't retie it, 
since we don't have a valid $r and we can't create one.

So we can use Apache::TestToString, but the tied buffer needs to be shared:

Index: Apache-Test/lib/Apache/
--- Apache-Test/lib/Apache/      (revision 161957)
+++ Apache-Test/lib/Apache/      (working copy)
@@ -506,8 +493,13 @@

  package Apache::TestToString;

+use Config;
      my $string = "";
+    if ($] >= 5.008 && $Config{useithreads} && $INC{''}) {
+        require threads::shared;
+        $string = &threads::shared::share(\$string);
+    }
      bless \$string;

and then we can write things like:

sub handler {
     my $r = shift;


     plan tests => $tests;

     threads->new(\&read_test)->join() for 1..$threads;



Clumsy, but at least it almost works.

I just need to figure out why Test::Builder doesn't do proper sub-test 
counting :9(

Test output counter mismatch [test 32]
ok 13 - tid: 0: pass 1:
Test output counter mismatch [test 33]
ok 14 - tid: 0: pass 2:
Test output counter mismatch [test 34]
ok 15 - tid: 0: pass 1:

even though was loaded before Test::Builder.

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message