From 9d2f494db0afc813e33cc8eacfa8b4a7c149ae05 Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Sun, 24 Aug 2014 22:34:29 +0900 Subject: [PATCH] Test refactoring --- prototype/tango-prototype/src/corfurl.erl | 19 +++++++++ prototype/tango-prototype/src/corfurl_flu.erl | 2 +- prototype/tango-prototype/test/tango_test.erl | 41 +++++++------------ 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/prototype/tango-prototype/src/corfurl.erl b/prototype/tango-prototype/src/corfurl.erl index cfb8f82..0a792e7 100644 --- a/prototype/tango-prototype/src/corfurl.erl +++ b/prototype/tango-prototype/src/corfurl.erl @@ -27,6 +27,7 @@ latest_projection_epoch_number/1]). -export([write_page/3, read_page/2, scan_forward/3, fill_page/2, trim_page/2]). +-export([simple_test_setup/5]). -include("corfurl.hrl"). @@ -351,3 +352,21 @@ project_to_chain(LPN, P) -> I = ((LPN - Start) rem tuple_size(Chains)) + 1, element(I, Chains) end. + +simple_test_setup(RootDir, BaseDirName, PageSize, NumPages, NumFLUs) -> + PDir = RootDir ++ "/" ++ BaseDirName ++ ".projection", + filelib:ensure_dir(PDir), + BaseDir = RootDir ++ "/flu." ++ BaseDirName ++ ".", + MyDir = fun(X) -> BaseDir ++ integer_to_list(X) end, + DeleteFLUData = fun() -> [ok = corfurl_util:delete_dir(MyDir(X)) || + X <- lists:seq(1, NumFLUs)] end, + DeleteFLUData(), + FLUs = [begin + element(2, corfurl_flu:start_link(MyDir(X), + PageSize, NumPages*PageSize)) + end || X <- lists:seq(1, NumFLUs)], + + {ok, Seq} = corfurl_sequencer:start_link(FLUs), + P0 = corfurl:new_simple_projection(PDir, 1, 1, 1*100, [FLUs]), + P1 = P0#proj{seq={Seq, unused, unused}}, + {FLUs, Seq, P1, DeleteFLUData}. diff --git a/prototype/tango-prototype/src/corfurl_flu.erl b/prototype/tango-prototype/src/corfurl_flu.erl index 4efb220..4feffa4 100644 --- a/prototype/tango-prototype/src/corfurl_flu.erl +++ b/prototype/tango-prototype/src/corfurl_flu.erl @@ -123,7 +123,7 @@ init({Dir, ExpPageSize, ExpMaxMem}) -> lclock_init(), MemFile = memfile_path(Dir), - filelib:ensure_dir(MemFile), + ok = filelib:ensure_dir(MemFile), {ok, FH} = file:open(MemFile, [read, write, raw, binary]), {_Version, MinEpoch, PageSize, MaxMem, TrimWatermark} = diff --git a/prototype/tango-prototype/test/tango_test.erl b/prototype/tango-prototype/test/tango_test.erl index c7f19f5..605fe97 100644 --- a/prototype/tango-prototype/test/tango_test.erl +++ b/prototype/tango-prototype/test/tango_test.erl @@ -48,37 +48,22 @@ pack_v1_test() -> Term <- [foo, {bar, baz, <<"yo">>}], Size <- lists:seq(100, 5000, 500)]. -run_test(Name, PageSize, NumPages, NumFLUs, FUN) -> - PDir = "./tmp." ++ Name, - BaseDir = "/tmp/" ++ atom_to_list(?MODULE) ++ ".", - MyDir = fun(X) -> BaseDir ++ integer_to_list(X) end, - Del = fun() -> [ok = corfurl_util:delete_dir(MyDir(X)) || - X <- lists:seq(1, NumFLUs)] end, - - Del(), - FLUs = [begin - element(2, corfurl_flu:start_link(MyDir(X), - PageSize, NumPages*PageSize)) - end || X <- lists:seq(1, NumFLUs)], - +run_test(RootDir, BaseDirName, PageSize, NumPages, NumFLUs, FUN) -> + {FLUs, Seq, P1, Del} = corfurl:simple_test_setup( + RootDir, BaseDirName, PageSize, NumPages, NumFLUs), try - {ok, Seq} = ?SEQ:start_link(FLUs), - try - P0 = corfurl:new_simple_projection(PDir, 1, 1, 1*100, [FLUs]), - P1 = P0#proj{seq={Seq, unused, unused}}, - FUN(PageSize, Seq, P1) - after - ?SEQ:stop(Seq) - end + FUN(PageSize, Seq, P1) after + ?SEQ:stop(Seq), [ok = corfurl_flu:stop(FLU) || FLU <- FLUs], Del() end. smoke_test() -> - ok = run_test("projection", 4096, 5*1024, 1, fun smoke_test_fun/3). + ok = run_test("/tmp", "projection", + 4096, 5*1024, 1, fun smoke_test_int/3). -smoke_test_fun(PageSize, Seq, P1) -> +smoke_test_int(PageSize, Seq, P1) -> ok = ?SEQ:set_tails(Seq, [{42,4242}, {43,4343}]), {ok, [4242, 4343]} = ?SEQ:get_tails(Seq, [42, 43]), @@ -94,9 +79,10 @@ smoke_test_fun(PageSize, Seq, P1) -> ok. write_forward_test() -> - ok = run_test("write_forward", 4096, 5*1024, 1, fun write_forward_test_fun/3). + ok = run_test("/tmp", "write_forward", + 4096, 5*1024, 1, fun write_forward_test_int/3). -write_forward_test_fun(PageSize, _Seq, P1) -> +write_forward_test_int(PageSize, _Seq, P1) -> StreamNum = 0, NumPages = 10, Pages = [term_to_binary({smoke, X}) || X <- lists:seq(1, NumPages)], @@ -118,9 +104,10 @@ write_stream_pages(Proj0, Pages, PageSize, InitialBackPs, StreamNum) -> Res. scan_backward_test() -> - ok = run_test("scan_backward", 4096, 5*1024, 1, fun scan_backward_test_fun/3). + ok = run_test("/tmp", "scan_backward", + 4096, 5*1024, 1, fun scan_backward_test_int/3). -scan_backward_test_fun(PageSize, _Seq, P1) -> +scan_backward_test_int(PageSize, _Seq, P1) -> StreamNum = 0, NumPages = 10, PageSeq = lists:seq(1, NumPages),