Fixed 'concurrent' inserts test

This commit is contained in:
Alexey Romanov
2010-11-19 10:12:39 +03:00
parent 1f45ee05f5
commit e4edf17f17

View File

@@ -145,15 +145,29 @@ select_many_records() ->
1024,
length(rows(sqlite3:sql_exec(ct, "select * from many_records;")))).
%% concurrent_inserts_test() ->
%% sqlite3:open(concurrent, [in_memory]), %% doing this test not in memory is much slower!
%% drop_table_if_exists(concurrent, t),
%% sqlite3:create_table(concurrent, t, [{id, integer}]),
%% [spawn(fun () -> sqlite3:write(concurrent, t, [{id, X}]) end) || X <- lists:seq(1, 1024)],
%% ?assertEqual(
%% 1024,
%% length(rows(sqlite3:read_all(concurrent, t)))),
%% sqlite3:close(concurrent). %% doesn't pass at the moment!
%% note that inserts are actually serialized by gen_server
concurrent_inserts_test() ->
N = 1024,
sqlite3:open(concurrent, [in_memory]), %% doing this test not in memory is much slower!
drop_table_if_exists(concurrent, t),
sqlite3:create_table(concurrent, t, [{id0, integer}]),
Self = self(),
[spawn(fun () ->
sqlite3:write(concurrent, t, [{id0, X}]),
Self ! {finished, N}
end) || X <- lists:seq(1, N)],
loop_concurrent_inserts(N),
?assertEqual(
N, length(rows(sqlite3:read_all(concurrent, t)))),
sqlite3:close(concurrent).
loop_concurrent_inserts(0) ->
ok;
loop_concurrent_inserts(N) ->
receive
{finished, _} ->
loop_concurrent_inserts(N - 1)
end.
nonexistent_table_info() ->
?assertEqual(table_does_not_exist, sqlite3:table_info(ct, nonexistent)).