I'm learning erlang and I have created a cache_server
module implementing gen_server behaviour
.
This module is responsible for creating ets tables
and has an api to insert, lookup, etc.
I wanted to make test suite for the module and to run test cases for insertion and lookup in one group of tests as a sequence because first function populates the table and other searches for inserted keys.
I tried to call cache_server:start_link([])
in init_per_suite
hook function of the suite but in test cases I don't see my cache_server
process when I call registered()
function.
And I get{noproc,{gen_server,call,[cache_server,{lookup,numbers,1}]}}
error.
I also tried to move call cache_server:start_link()
from the init_per_suite to the first test case but in the subsequent test cases the process gets unavailable.
When I test my code by hands using rebar3 shell, everything works as expected.
Is it possible to share a named gen_server process between test cases in common test test suite?
1条答案
按热度按时间guicsvcw1#
尝试在
init_per_testcase
中调用cache_server:start_link()
。由于此函数在每个测试用例之前执行,因此您还需要停止end_per_testcase
中该高速缓存_server进程。另一个选择是将所有与
cache_server
相关的测试用例分组到一个组中,在init_per_group
中调用cache_server:start_link()
,并在end_per_group
中停止该过程