Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first version of spec tests for S17

git-svn-id: http://svn.pugscode.org/pugs@19852 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
commit 2052e29220a5c324678d58294b9d5492013404c9 1 parent 60e954c
buchetc authored
Showing with 63 additions and 0 deletions.
  1. +63 −0 S17-async/async.t
View
63 S17-async/async.t
@@ -0,0 +1,63 @@
+use v6-alpha;
+use Test;
+
+
+
+plan 8;
+
+# try to stop duration of a simple async call
+my $timestamp = time;
+
+# L<S17/Threads>
+async {
+ ok 1, 'async call started';
+};
+
+my $async_duration = time - $timestamp;
+
+# now if the follwing call is really asynchron, next time stop should
+# be smaller than C<$async_duration + .5>
+
+$timestamp = time;
+my $thr = async {
+ sleep 1;
+};
+
+ok time - $timestamp < $async_duration + .5, "yes, 'Im out of sync!";
+
+#?pugs todo bug
+todo :pugs<6.2.14>; # hopefully :-)
+ok $thr, 'stringify a thread';
+
+todo :pugs<6.2.14>; # hopefully :-)
+ok int $thr, 'numerify a thread should be the thread id';
+
+isnt int $thr, $*PID, 'childs id is not parents thread id';
+
+$thr.join;
+
+# try two async calls to something
+sub do_something_very_important {
+ return 1;
+}
+
+async { ok do_something_very_important(),'very important: first try' };
+async { ok do_something_very_important(),'very important: second try' };
+
+# try to construct race condition
+# see Stevens 'UNIX network programming' 23.17
+my $counter = 0;
+sub doit {
+ my $val = $counter; sleep .0001; $counter = $val + 1;
+}
+
+loop (my $i = 0; $i < 500; $i++) {
+
+ async { doit(); };
+ async { doit(); };
+
+}
+
+ok $counter < 1000, 'the race condition strikes back';
+
+#diag( $counter );
Please sign in to comment.
Something went wrong with that request. Please try again.