fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / t / pmc / scheduler.t
blobca696e3a2595292c0b6476de60e6c4e71d537015
1 #!./parrot
2 # Copyright (C) 2007-2010, Parrot Foundation.
3 # $Id$
5 =head1 NAME
7 t/pmc/scheduler.t - Concurrency Scheduler
9 =head1 SYNOPSIS
11     % prove t/pmc/scheduler.t
13 =head1 DESCRIPTION
15 Tests the concurrency scheduler PMC.
17 =cut
20 .sub main :main
21     .include 'test_more.pir'
22     plan(6)
24     create_and_set_attributes()
25     create_concurrent_scheduler_with_init()
26     add_event_and_handler_to_scheduler()
27 .end
29 .sub create_and_set_attributes
30     $P0 = new ['Scheduler']
31     $P1 = new ['Task']
33     push $P0, $P1
35     $P2 = pop $P0
37     if null $P2 goto no_task
38       $P3 = getattribute $P2, 'status'
39       $S0 = $P3
40       is($S0, "created", "got task")
41       goto got_task
43 no_task:
44       ok(0,"no task to retrieve")
46 got_task:
48       ok(1, "didn't explode")
49 .end
51 .sub create_concurrent_scheduler_with_init
52     .local pmc data
53     data       = new ['Hash']
55     .local pmc id
56     id         = new ['Integer']
57     id         = 128
58     data['id'] = id
60     $P0 = new ['Scheduler'], data
61     $P1 = new ['Task']
63     push $P0, $P1
65     $P2 = pop $P0
67     if null $P2 goto no_task
68       $P3 = getattribute $P2, 'status'
69       $S0 = $P3
70       is($S0, "created", "status is ok")
71       goto got_task
73 no_task:
74       ok(0, 'no task to retrieve')
76 got_task:
77     ok(1, "got a task")
79     push_eh bad_initializer
80       $P0 = new ['Scheduler'], id
81     pop_eh
83     ok(0, "No exception on invalid initializer?  Uh oh!")
84     end
86 bad_initializer:
87     ok(1, "Caught exception on bad initializer")
88 .end
91 .sub add_event_and_handler_to_scheduler
92     .local pmc handler, handler_init, handler_sub
93     .local pmc event, event_init
94     handler_init = new ['Hash']
95     handler_init['type'] = 'myevent'
96     handler_sub = get_global 'my_event_handler'
97     handler_init['code'] = handler_sub
98     handler = new ['EventHandler'], handler_init
100     addhandler handler
102     event_init = new ['Hash']
103     event_init['type'] = 'event'
104     event_init['subtype'] = 'myevent'
105     event = new ['Task'], event_init
107     schedule event
109 .end
111 .sub my_event_handler
112     .param pmc handler
113     .param pmc handledtask
114     ok(1, "called event handler")
115 .end
117 # Local Variables:
118 #   mode: pir
119 #   fill-column: 100
120 # End:
121 # vim: expandtab shiftwidth=4 ft=pir: