erlang 在init_per_suite中创建的命名gen_server进程在测试中不存在

enxuqcxy  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(142)

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?

guicsvcw

guicsvcw1#

尝试在init_per_testcase中调用cache_server:start_link()。由于此函数在每个测试用例之前执行,因此您还需要停止end_per_testcase中该高速缓存_server进程。
另一个选择是将所有与cache_server相关的测试用例分组到一个组中,在init_per_group中调用cache_server:start_link(),并在end_per_group中停止该过程

相关问题