Annotate

spec/util_async_spec.lua @ 8607:62bb06cf8a43

util.async: Add tests to specifically cover error handling
author Matthew Wild <mwild1@gmail.com>
date Fri, 16 Mar 2018 17:50:16 +0000
parent 8605:3a1efc0532cb
child 8608:a2e6caf5848d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8605
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local async = require "util.async";
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 describe("util.async", function()
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local debug = false;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local print = print;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 if debug then
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 require "util.logger".add_simple_sink(print);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 else
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 print = function () end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local function new(func, name)
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local log = {};
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 return async.runner(func, setmetatable({}, {
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 __index = function (_, event)
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 return function (runner, err)
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 print(name, "event", event, err)
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 print "--"
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 table.insert(log, { event = event, err = err });
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 end;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 })), log;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 describe("#runner", function()
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 it("should work", function()
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local r, l = new(function (item) assert(type(item) == "number") end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 r:run(1);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 r:run(2);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 end);
8607
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
29
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
30 it("should be ready after creation", function ()
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
31 local r = async.runner(function (item) end);
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
32 assert.equal(r.state, "ready");
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
33 end);
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
34
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
35 describe("#errors", function ()
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
36 local last_processed_item, last_error;
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
37 local r;
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
38 r = async.runner(function (item)
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
39 if item == "error" then
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
40 error({ e = "test error" });
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
41 end
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
42 last_processed_item = item;
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
43 end, {
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
44 error = function (runner, err)
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
45 assert.equal(r, runner);
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
46 last_error = err;
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
47 end;
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
48 });
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
49
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
50 randomize(false);
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
51
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
52 it("should notify", function ()
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
53 local last_processed_item, last_error;
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
54 local r;
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
55 r = async.runner(function (item)
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
56 if item == "error" then
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
57 error({ e = "test error" });
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
58 end
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
59 last_processed_item = item;
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
60 end, {
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
61 error = function (runner, err)
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
62 assert.equal(r, runner);
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
63 last_error = err;
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
64 end;
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
65 });
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
66
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
67 r:run("hello");
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
68 assert.equal(r.state, "ready");
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
69 assert.equal(last_processed_item, "hello");
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
70
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
71 assert.equal(last_error, nil);
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
72 r:run("error");
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
73 assert.is_table(last_error);
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
74 assert.equal(last_error.e, "test error");
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
75 last_error = nil;
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
76 assert.equal(r.state, "ready");
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
77 assert.equal(last_processed_item, "hello");
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
78 end);
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
79 it("should not be fatal to the runner", function ()
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
80 r:run("world");
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
81 assert.equal(r.state, "ready");
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
82 assert.equal(last_processed_item, "world");
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
83 end);
62bb06cf8a43 util.async: Add tests to specifically cover error handling
Matthew Wild <mwild1@gmail.com>
parents: 8605
diff changeset
84 end);
8605
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 describe("#waiter", function()
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 it("should work", function ()
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 local wait, done;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 local r, l = new(function (item)
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 assert(type(item) == "number")
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 if item == 3 then
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 wait, done = async.waiter();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 wait();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 r:run(1);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 r:run(2);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 r:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 assert(r.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 done();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 --for k, v in ipairs(l) do print(k,v) end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 it("should work", function ()
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 --------------------
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 local wait, done;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 local last_item = 0;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 local r, l = new(function (item)
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 assert(type(item) == "number")
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 assert(item == last_item + 1);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 last_item = item;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 if item == 3 then
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 wait, done = async.waiter();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 wait();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 r:run(1);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 r:run(2);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 r:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 assert(r.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 r:run(4);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 assert(r.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 done();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 --for k, v in ipairs(l) do print(k,v) end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 it("should work", function ()
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 --------------------
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 local wait, done;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 local last_item = 0;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 local r, l = new(function (item)
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 assert(type(item) == "number")
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 assert((item == last_item + 1) or item == 3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 last_item = item;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 if item == 3 then
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 wait, done = async.waiter();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 wait();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 r:run(1);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 r:run(2);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 local dones = {};
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 r:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 assert(r.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 r:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 assert(r.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 r:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 assert(r.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 r:run(4);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 assert(r.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 for i = 1, 3 do
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 done();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 if i < 3 then
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 assert(r.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 --for k, v in ipairs(l) do print(k,v) end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 it("should work", function ()
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 --------------------
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 local wait, done;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 local last_item = 0;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 local r, l = new(function (item)
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179 assert(type(item) == "number")
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180 assert((item == last_item + 1) or item == 3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 last_item = item;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
182 if item == 3 then
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183 wait, done = async.waiter();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 wait();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188 r:run(1);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190 r:run(2);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
191 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
192
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
193 local dones = {};
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
194 r:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195 assert(r.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
196 r:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
197 assert(r.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
198
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
199 for i = 1, 2 do
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
200 done();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
201 if i < 2 then
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
202 assert(r.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
203 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
204 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
205
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
206 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
207 r:run(4);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
208 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
209
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
210 assert(r.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
211 --for k, v in ipairs(l) do print(k,v) end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
212 end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
213 it("should work with multiple runners in parallel", function ()
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
214 -- Now with multiple runners
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
215 --------------------
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216 local wait1, done1;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
217 local last_item1 = 0;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
218 local r1, l1 = new(function (item)
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
219 assert(type(item) == "number")
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
220 assert((item == last_item1 + 1) or item == 3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
221 last_item1 = item;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
222 if item == 3 then
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
223 wait1, done1 = async.waiter();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
224 wait1();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
225 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
226 end, "r1");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
227
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
228 local wait2, done2;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
229 local last_item2 = 0;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
230 local r2, l2 = new(function (item)
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
231 assert(type(item) == "number")
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
232 assert((item == last_item2 + 1) or item == 3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
233 last_item2 = item;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
234 if item == 3 then
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
235 wait2, done2 = async.waiter();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
236 wait2();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
237 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
238 end, "r2");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
239
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
240 r1:run(1);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
241 assert(r1.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
242 r1:run(2);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
243 assert(r1.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
244
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
245 local dones = {};
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
246 r1:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
247 assert(r1.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
248 r1:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
249 assert(r1.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
250
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
251 r2:run(1);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
252 assert(r1.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
253 assert(r2.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
254
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
255 r2:run(2);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
256 assert(r1.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
257 assert(r2.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
258
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
259 r2:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
260 assert(r1.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
261 assert(r2.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
262 done2();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
263
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
264 r2:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
265 assert(r1.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
266 assert(r2.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
267 done2();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
268
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
269 r2:run(4);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
270 assert(r1.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
271 assert(r2.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
272
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
273 for i = 1, 2 do
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
274 done1();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
275 if i < 2 then
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
276 assert(r1.state == "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
277 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
278 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
279
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
280 assert(r1.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
281 r1:run(4);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
282 assert(r1.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
283
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
284 assert(r1.state == "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
285 --for k, v in ipairs(l1) do print(k,v) end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
286 end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
287 it("should work work with multiple runners in parallel", function ()
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
288 --------------------
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
289 local wait1, done1;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
290 local last_item1 = 0;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
291 local r1, l1 = new(function (item)
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
292 print("r1 processing ", item);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
293 assert(type(item) == "number")
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
294 assert((item == last_item1 + 1) or item == 3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
295 last_item1 = item;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
296 if item == 3 then
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
297 wait1, done1 = async.waiter();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
298 wait1();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
299 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
300 end, "r1");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
301
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
302 local wait2, done2;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
303 local last_item2 = 0;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
304 local r2, l2 = new(function (item)
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
305 print("r2 processing ", item);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
306 assert.is_number(item);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
307 assert((item == last_item2 + 1) or item == 3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
308 last_item2 = item;
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
309 if item == 3 then
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
310 wait2, done2 = async.waiter();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
311 wait2();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
312 end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
313 end, "r2");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
314
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
315 r1:run(1);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
316 assert.equal(r1.state, "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
317 r1:run(2);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
318 assert.equal(r1.state, "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
319
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
320 r1:run(5);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
321 assert.equal(r1.state, "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
322
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
323 local dones = {};
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
324 r1:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
325 assert.equal(r1.state, "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
326 r1:run(5); -- Will error, when we get to it
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
327 assert.equal(r1.state, "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
328 done1();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
329 assert.equal(r1.state, "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
330 r1:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
331 assert.equal(r1.state, "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
332
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
333 r2:run(1);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
334 assert.equal(r1.state, "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
335 assert.equal(r2.state, "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
336
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
337 r2:run(2);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
338 assert.equal(r1.state, "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
339 assert.equal(r2.state, "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
340
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
341 r2:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
342 assert.equal(r1.state, "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
343 assert.equal(r2.state, "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
344
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
345 done2();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
346 assert.equal(r1.state, "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
347 assert.equal(r2.state, "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
348
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
349 r2:run(3);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
350 assert.equal(r1.state, "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
351 assert.equal(r2.state, "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
352
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
353 done2();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
354 assert.equal(r1.state, "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
355 assert.equal(r2.state, "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
356
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
357 r2:run(4);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
358 assert.equal(r1.state, "waiting");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
359 assert.equal(r2.state, "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
360
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
361 done1();
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
362
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
363 assert.equal(r1.state, "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
364 r1:run(4);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
365 assert.equal(r1.state, "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
366
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
367 assert.equal(r1.state, "ready");
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
368 --for k, v in ipairs(l1) do print(k,v) end
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
369 end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
370 end);
3a1efc0532cb util.async: Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
371 end);