syn_register_processes_SUITE.erl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. -module(syn_register_processes_SUITE).
  2. %% callbacks
  3. -export([all/0]).
  4. -export([init_per_suite/1, end_per_suite/1]).
  5. -export([groups/0, init_per_group/2, end_per_group/2]).
  6. %% tests
  7. -export([
  8. single_node_when_mnesia_is_ram_simple_registration/1
  9. ]).
  10. %% include
  11. -include_lib("common_test/include/ct.hrl").
  12. %% ===================================================================
  13. %% Callbacks
  14. %% ===================================================================
  15. %% -------------------------------------------------------------------
  16. %% Function: all() -> GroupsAndTestCases | {skip,Reason}
  17. %% GroupsAndTestCases = [{group,GroupName} | TestCase]
  18. %% GroupName = atom()
  19. %% TestCase = atom()
  20. %% Reason = term()
  21. %% -------------------------------------------------------------------
  22. all() ->
  23. [
  24. {group, single_node_process_registration}
  25. ].
  26. %% -------------------------------------------------------------------
  27. %% Function: groups() -> [Group]
  28. %% Group = {GroupName,Properties,GroupsAndTestCases}
  29. %% GroupName = atom()
  30. %% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]
  31. %% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]
  32. %% TestCase = atom()
  33. %% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}
  34. %% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |
  35. %% repeat_until_any_ok | repeat_until_any_fail
  36. %% N = integer() | forever
  37. %% -------------------------------------------------------------------
  38. groups() ->
  39. [
  40. {single_node_process_registration, [shuffle], [
  41. single_node_when_mnesia_is_ram_simple_registration
  42. ]}
  43. ].
  44. %% -------------------------------------------------------------------
  45. %% Function: init_per_suite(Config0) ->
  46. %% Config1 | {skip,Reason} |
  47. %% {skip_and_save,Reason,Config1}
  48. %% Config0 = Config1 = [tuple()]
  49. %% Reason = term()
  50. %% -------------------------------------------------------------------
  51. init_per_suite(Config) ->
  52. %% config
  53. [
  54. {slave_node_short_name, syn_slave}
  55. | Config
  56. ].
  57. %% -------------------------------------------------------------------
  58. %% Function: end_per_suite(Config0) -> void() | {save_config,Config1}
  59. %% Config0 = Config1 = [tuple()]
  60. %% -------------------------------------------------------------------
  61. end_per_suite(_Config) -> ok.
  62. %% -------------------------------------------------------------------
  63. %% Function: init_per_group(GroupName, Config0) ->
  64. %% Config1 | {skip,Reason} |
  65. %% {skip_and_save,Reason,Config1}
  66. %% GroupName = atom()
  67. %% Config0 = Config1 = [tuple()]
  68. %% Reason = term()
  69. %% -------------------------------------------------------------------
  70. init_per_group(_GroupName, Config) -> Config.
  71. %% -------------------------------------------------------------------
  72. %% Function: end_per_group(GroupName, Config0) ->
  73. %% void() | {save_config,Config1}
  74. %% GroupName = atom()
  75. %% Config0 = Config1 = [tuple()]
  76. %% -------------------------------------------------------------------
  77. end_per_group(_GroupName, _Config) ->
  78. clean_after_test().
  79. %% ===================================================================
  80. %% Tests
  81. %% ===================================================================
  82. single_node_when_mnesia_is_ram_simple_registration(_Config) ->
  83. %% set schema location
  84. application:set_env(mnesia, schema_location, ram),
  85. %% start
  86. ok = syn:start(),
  87. %% start process
  88. Pid = start_process(),
  89. %% retrieve
  90. undefined = syn:find_by_key(<<"my proc">>),
  91. %% register
  92. syn:register(<<"my proc">>, Pid),
  93. %% retrieve
  94. Pid = syn:find_by_key(<<"my proc">>),
  95. %% kill process
  96. kill_process(Pid),
  97. timer:sleep(100),
  98. %% retrieve
  99. undefined = syn:find_by_key(<<"my proc">>).
  100. %% ===================================================================
  101. %% Internal
  102. %% ===================================================================
  103. clean_after_test() ->
  104. %% stop mnesia
  105. mnesia:stop(),
  106. %% delete schema
  107. mnesia:delete_schema([node()]),
  108. %% stop syn
  109. syn:stop().
  110. start_process() ->
  111. Pid = spawn(?MODULE, process_main, []),
  112. Pid.
  113. kill_process(Pid) ->
  114. exit(Pid, kill).
  115. process_main() ->
  116. receive
  117. shutdown -> ok
  118. end.