forked from Eonblast/Emysql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Henning
committed
Feb 1, 2012
1 parent
88a9bb6
commit 991007c
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
%% Test for Issue 20, courtesy Bart van Deenen, 1 Feb 2012. | ||
%% The bug was a missing check of what pool a queued execution was waiting for. | ||
%% The fix included introducing wait queues per pool. | ||
%% To run this test, make a folder test, move this file into it, | ||
%% move emysql into test/emysql, clone eunit into test/eunit: | ||
%% $ git clone https://github.com/abhay/eunit.git # then do | ||
%% $ cd emysql && make && cd .. && cd eunit && make && cd .. | ||
%% $ erlc issue20.erl && erl -pa emysql/ebin -s issue20 test -s init stop -noshell | ||
%% /hd 2 1 12 | ||
|
||
-module(issue20). | ||
|
||
-include_lib("eunit/include/eunit.hrl"). | ||
-include_lib("emysql/include/emysql.hrl"). | ||
|
||
-compile(export_all). | ||
|
||
test() -> | ||
|
||
crypto:start(), | ||
application:start(emysql), | ||
|
||
try emysql:remove_pool(test1) catch _:_ -> ok end, | ||
try emysql:remove_pool(test2) catch _:_ -> ok end, | ||
try emysql:remove_pool(test3) catch _:_ -> ok end, | ||
|
||
emysql:add_pool(test1, 1, "demo", "demo", "localhost", 3306, "emysql1", utf8), | ||
emysql:add_pool(test2, 1, "demo", "demo", "localhost", 3306, "emysql2", utf8), | ||
emysql:add_pool(test3, 1, "demo", "demo", "localhost", 3306, "emysql1", utf8), | ||
|
||
?assertMatch( #result_packet{}, emysql:execute(test1, "select a from test")), | ||
|
||
?assertMatch( #result_packet{}, emysql:execute(test2, "select b from test")), | ||
|
||
?assertMatch( #result_packet{}, emysql:execute(test3, "select A from test")), | ||
|
||
F=fun() -> | ||
timer:sleep(100+random:uniform(500)), | ||
?assertMatch( #result_packet{}, emysql:execute(test2, "select b from test")), | ||
?assertMatch( #result_packet{}, emysql:execute(test3, "select A from test")), | ||
ok | ||
end, | ||
[spawn(F) || _ <- lists:seq(1,5)], | ||
timer:sleep(1000), | ||
ok. |