tests/test_util_async.lua
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Sat, 15 Apr 2017 01:21:55 +0100
changeset 8216 e1272aeef31c
parent 8212 39f24de4f53f
permissions -rw-r--r--
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7440
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     1
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     2
-- Test passing nil to runner
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     3
-- Test runners work correctly after errors (coroutine gets recreated)
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     4
-- What happens if an error is thrown, but more items are in the queue? (I think runner might stall)
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     5
-- Test errors thrown halfway through a queue
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     6
-- Multiple runners
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     7
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     8
function runner(new_runner, async)
8212
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
     9
	local function new(func, name)
7440
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    10
		local log = {};
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    11
		return new_runner(func, setmetatable({}, {
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    12
			__index = function (_, event)
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    13
				return function (runner, err)
8212
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
    14
					print(name, "event", event, err)
7440
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    15
					table.insert(log, { event = event, err = err });
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    16
				end;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    17
			end;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    18
		})), log;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    19
	end
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    20
	
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    21
	--------------------
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    22
	local r, l = new(function (item) assert(type(item) == "number") end);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    23
	r:run(1);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    24
	r:run(2);
8212
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
    25
	--for k, v in ipairs(l) do print(k,v) end
7440
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    26
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    27
	--------------------
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    28
	local wait, done;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    29
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    30
	local r, l = new(function (item)
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    31
		assert(type(item) == "number")
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    32
		if item == 3 then
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    33
			wait, done = async.waiter();
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    34
			wait();
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    35
		end
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    36
	end);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    37
	
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    38
	r:run(1);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    39
	assert(r.state == "ready");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    40
	r:run(2);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    41
	assert(r.state == "ready");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    42
	r:run(3);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    43
	assert(r.state == "waiting");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    44
	done();
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    45
	assert(r.state == "ready");
8212
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
    46
	--for k, v in ipairs(l) do print(k,v) end
7440
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    47
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    48
	--------------------
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    49
	local wait, done;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    50
	local last_item = 0;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    51
	local r, l = new(function (item)
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    52
		assert(type(item) == "number")
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    53
		assert(item == last_item + 1);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    54
		last_item = item;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    55
		if item == 3 then
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    56
			wait, done = async.waiter();
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    57
			wait();
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    58
		end
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    59
	end);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    60
	
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    61
	r:run(1);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    62
	assert(r.state == "ready");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    63
	r:run(2);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    64
	assert(r.state == "ready");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    65
	r:run(3);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    66
	assert(r.state == "waiting");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    67
	r:run(4);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    68
	assert(r.state == "waiting");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    69
	done();
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    70
	assert(r.state == "ready");
8212
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
    71
	--for k, v in ipairs(l) do print(k,v) end
7440
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    72
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    73
	--------------------
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    74
	local wait, done;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    75
	local last_item = 0;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    76
	local r, l = new(function (item)
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    77
		assert(type(item) == "number")
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    78
		assert((item == last_item + 1) or item == 3);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    79
		last_item = item;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    80
		if item == 3 then
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    81
			wait, done = async.waiter();
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    82
			wait();
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    83
		end
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    84
	end);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    85
	
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    86
	r:run(1);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    87
	assert(r.state == "ready");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    88
	r:run(2);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    89
	assert(r.state == "ready");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    90
	
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    91
	local dones = {};
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    92
	r:run(3);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    93
	assert(r.state == "waiting");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    94
	r:run(3);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    95
	assert(r.state == "waiting");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    96
	r:run(3);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    97
	assert(r.state == "waiting");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    98
	r:run(4);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    99
	assert(r.state == "waiting");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   100
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   101
	for i = 1, 3 do
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   102
		done();
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   103
		if i < 3 then
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   104
			assert(r.state == "waiting");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   105
		end
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   106
	end
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   107
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   108
	assert(r.state == "ready");
8212
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   109
	--for k, v in ipairs(l) do print(k,v) end
7440
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   110
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   111
	--------------------
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   112
	local wait, done;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   113
	local last_item = 0;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   114
	local r, l = new(function (item)
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   115
		assert(type(item) == "number")
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   116
		assert((item == last_item + 1) or item == 3);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   117
		last_item = item;
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   118
		if item == 3 then
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   119
			wait, done = async.waiter();
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   120
			wait();
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   121
		end
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   122
	end);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   123
	
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   124
	r:run(1);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   125
	assert(r.state == "ready");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   126
	r:run(2);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   127
	assert(r.state == "ready");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   128
	
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   129
	local dones = {};
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   130
	r:run(3);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   131
	assert(r.state == "waiting");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   132
	r:run(3);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   133
	assert(r.state == "waiting");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   134
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   135
	for i = 1, 2 do
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   136
		done();
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   137
		if i < 2 then
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   138
			assert(r.state == "waiting");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   139
		end
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   140
	end
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   141
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   142
	assert(r.state == "ready");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   143
	r:run(4);
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   144
	assert(r.state == "ready");
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   145
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   146
	assert(r.state == "ready");
8212
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   147
	--for k, v in ipairs(l) do print(k,v) end
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   148
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   149
	-- Now with multiple runners
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   150
	--------------------
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   151
	local wait1, done1;
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   152
	local last_item1 = 0;
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   153
	local r1, l1 = new(function (item)
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   154
		assert(type(item) == "number")
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   155
		assert((item == last_item1 + 1) or item == 3);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   156
		last_item1 = item;
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   157
		if item == 3 then
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   158
			wait1, done1 = async.waiter();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   159
			wait1();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   160
		end
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   161
	end, "r1");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   162
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   163
	local wait2, done2;
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   164
	local last_item2 = 0;
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   165
	local r2, l2 = new(function (item)
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   166
		assert(type(item) == "number")
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   167
		assert((item == last_item2 + 1) or item == 3);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   168
		last_item2 = item;
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   169
		if item == 3 then
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   170
			wait2, done2 = async.waiter();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   171
			wait2();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   172
		end
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   173
	end, "r2");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   174
	
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   175
	r1:run(1);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   176
	assert(r1.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   177
	r1:run(2);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   178
	assert(r1.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   179
	
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   180
	local dones = {};
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   181
	r1:run(3);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   182
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   183
	r1:run(3);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   184
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   185
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   186
	r2:run(1);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   187
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   188
	assert(r2.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   189
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   190
	r2:run(2);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   191
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   192
	assert(r2.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   193
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   194
	r2:run(3);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   195
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   196
	assert(r2.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   197
	done2();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   198
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   199
	r2:run(3);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   200
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   201
	assert(r2.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   202
	done2();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   203
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   204
	r2:run(2);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   205
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   206
	assert(r2.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   207
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   208
	for i = 1, 2 do
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   209
		done1();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   210
		if i < 2 then
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   211
			assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   212
		end
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   213
	end
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   214
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   215
	assert(r1.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   216
	r1:run(4);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   217
	assert(r1.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   218
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   219
	assert(r1.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   220
	--for k, v in ipairs(l1) do print(k,v) end
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   221
	
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   222
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   223
	--------------------
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   224
	local wait1, done1;
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   225
	local last_item1 = 0;
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   226
	local r1, l1 = new(function (item)
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   227
		assert(type(item) == "number")
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   228
		assert((item == last_item1 + 1) or item == 3);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   229
		last_item1 = item;
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   230
		if item == 3 then
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   231
			wait1, done1 = async.waiter();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   232
			wait1();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   233
		end
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   234
	end, "r1");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   235
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   236
	local wait2, done2;
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   237
	local last_item2 = 0;
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   238
	local r2, l2 = new(function (item)
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   239
		assert(type(item) == "number")
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   240
		assert((item == last_item2 + 1) or item == 3);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   241
		last_item2 = item;
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   242
		if item == 3 then
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   243
			wait2, done2 = async.waiter();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   244
			wait2();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   245
		end
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   246
	end, "r2");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   247
	
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   248
	r1:run(1);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   249
	assert(r1.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   250
	r1:run(2);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   251
	assert(r1.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   252
	
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   253
	r1:run(5);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   254
	assert(r1.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   255
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   256
	local dones = {};
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   257
	r1:run(3);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   258
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   259
	r1:run(5); -- Will error, when we get to it
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   260
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   261
	r1:run(3);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   262
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   263
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   264
	r2:run(1);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   265
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   266
	assert(r2.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   267
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   268
	r2:run(2);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   269
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   270
	assert(r2.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   271
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   272
	r2:run(3);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   273
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   274
	assert(r2.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   275
	done2();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   276
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   277
	r2:run(3);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   278
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   279
	assert(r2.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   280
	done2();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   281
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   282
	r2:run(2);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   283
	assert(r1.state == "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   284
	assert(r2.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   285
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   286
	for i = 1, 2 do
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   287
		done1();
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   288
		if i < 2 then
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   289
			assert_equal(r1.state, "waiting");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   290
		end
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   291
	end
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   292
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   293
	assert(r1.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   294
	r1:run(4);
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   295
	assert(r1.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   296
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   297
	assert(r1.state == "ready");
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   298
	--for k, v in ipairs(l1) do print(k,v) end
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   299
	
39f24de4f53f tests: Add failing tests for util.async
Matthew Wild <mwild1@gmail.com>
parents: 7440
diff changeset
   300
	
7440
ff74188488ab tests: Add initial tests for util.async
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   301
end