Test suite for checking concurrency in erlang

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Test suite for checking concurrency in erlang

Abhishek Ranjan-2

Hello,

I wanted to write a test case which can show me that when one single code base is used and accessed by two or more individuals at the same time then how does it behaves(I basically want to test for concurrancy). I have chosen the code base as a tic-tac-toe game present on this link

I have changed the code a bit though and have attached the files in this mail.

Now I tried common_test and wrote the following module testing2

-module(testing2).
-include_lib("common_test/include/ct.hrl").
%% ====================================================================
%% API functions
%% ====================================================================
-export([all/0, groups/0, init_per_group/2, end_per_group/2]).
-export([test1/1,test2/1]).
%% ====================================================================
%% Internal functions
%% ====================================================================
all() -> [{group, session}].

groups() -> [{session,
              [],
              [{group, clients}]},
             {clients,
              [parallel, {repeat, 1}],
              [test1, test2]}].

init_per_group(session, Config) ->
   gameserver:start(),
    Config;
init_per_group(_, Config) ->
    Config.

end_per_group(session, _Config) ->
    gameclient:stop();
end_per_group(_, _Config) ->
    ok.


test1(_Config)->
  
Abhishek=gameclient:login("Abhishek"),
Dharun=gameclient:login("Dharun"),
 
 
gameclient:new_game(Abhishek),
 
 timer:sleep(5),
 
 gameclient:make_move(Abhishek, a1),
 timer:sleep(5),
 gameclient:make_move(Dharun, b2),
 timer:sleep(5),
 gameclient:make_move(Abhishek, a2),
 timer:sleep(5), 
 gameclient:make_move(Dharun, c3),
 timer:sleep(5),
 gameclient:make_move(Abhishek, a3).



test2(_Config)->
  
Abhijeet=gameclient:login("Abhijeet"),
Ranjan=gameclient:login("Ranjan"),
 
 
gameclient:new_game(Abhijeet),
 timer:sleep(5),
 
 gameclient:make_move(Abhijeet, a1),
 timer:sleep(5),
 gameclient:make_move(Ranjan, b2),
 timer:sleep(5),
 gameclient:make_move(Abhijeet, a2),
 timer:sleep(5), 
 gameclient:make_move(Ranjan, c3),
 timer:sleep(5),
 gameclient:make_move(Abhijeet, a3).


Now when I see the logs of ct I find the following output:

for test1()->

=== Started at 2017-09-19 16:37:16

“Welcome to tictactoe server!”
“Welcome to tictactoe server!”
“Ready to rumble against Abhishek!”
“Ready to rumble against Dharun!”


=== Ended at 2017-09-19 16:37:16
=== successfully completed test case
=== Returned value: {make_move,a3}

for test2()->



=== Started at 2017-09-19 16:37:16


“Welcome to tictactoe server!”

“Welcome to tictactoe server!”

“Ready to rumble against Ranjan!”

“Ready to rumble against Abhijeet!”

“It is not your turn yet!”

“It is not your turn yet!”



=== Ended at 2017-09-19 16:37:16
=== successfully completed test case
=== Returned value: {make_move,a3}


But I expected the output of both the games in the logs as I am running them in parallel.

Can anyone suggest me what am I missing and how to go about it?

Thank you.

Best Regards,

Abhishek


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

gameclient.txt (2K) Download Attachment
gameserver.txt (5K) Download Attachment
tictactoe.txt (5K) Download Attachment
serv_util.txt (504 bytes) Download Attachment