From a64a09338ddafa6bb5628d1404d2e64f0bb6efc3 Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Tue, 25 Feb 2014 16:15:01 +0900 Subject: [PATCH] Fix broken EUnit tests (been in PULSE land too long) --- prototype/corfurl/src/corfurl.erl | 5 +- prototype/corfurl/src/corfurl_flu.erl | 53 ++++++++---- prototype/corfurl/src/corfurl_sequencer.erl | 74 ++++++----------- prototype/corfurl/test/corfurl_pulse.erl | 2 + .../corfurl/test/corfurl_sequencer_test.erl | 80 +++++++++++++++++++ prototype/corfurl/test/corfurl_test.erl | 2 +- 6 files changed, 151 insertions(+), 65 deletions(-) create mode 100644 prototype/corfurl/test/corfurl_sequencer_test.erl diff --git a/prototype/corfurl/src/corfurl.erl b/prototype/corfurl/src/corfurl.erl index 6936063..38332a8 100644 --- a/prototype/corfurl/src/corfurl.erl +++ b/prototype/corfurl/src/corfurl.erl @@ -64,7 +64,10 @@ append_page(Sequencer, P, Page, Retries) when Retries < 50 -> write_single_page(#proj{epoch=Epoch} = P, LPN, Page) -> Chain = project_to_chain(LPN, P), - write_single_page_to_chain(Chain, Chain, Epoch, LPN, Page, 1, ok). + write_single_page_to_chain(Chain, Chain, Epoch, LPN, Page, 1). + +write_single_page_to_chain(Chain, Chain, Epoch, LPN, Page, Nth) -> + write_single_page_to_chain(Chain, Chain, Epoch, LPN, Page, Nth, ok). write_single_page_to_chain([], _Chain, _Epoch, _LPN, _Page, _Nth, Reply) -> Reply; diff --git a/prototype/corfurl/src/corfurl_flu.erl b/prototype/corfurl/src/corfurl_flu.erl index c55dc72..fc73173 100644 --- a/prototype/corfurl/src/corfurl_flu.erl +++ b/prototype/corfurl/src/corfurl_flu.erl @@ -93,14 +93,15 @@ trim(Pid, Epoch, LogicalPN) fill(Pid, Epoch, LogicalPN) when is_integer(Epoch), Epoch > 0, is_integer(LogicalPN), LogicalPN > 0 -> - g_call(Pid, {fill, Epoch, LogicalPN}, infinity). + Res = g_call(Pid, {fill, Epoch, LogicalPN}, infinity), + undo_special_pulse_test_result(Res). g_call(Pid, Arg, Timeout) -> - LC1 = lamport_clock:get(), + LC1 = lclock_get(), msc(self(), Pid, Arg), {Res, LC2} = gen_server:call(Pid, {Arg, LC1}, Timeout), msc(Pid, self(), Res), - lamport_clock:update(LC2), + lclock_update(LC2), Res. -ifdef(TEST). @@ -119,7 +120,7 @@ get__trim_watermark(Pid) -> %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% init({Dir, ExpPageSize, ExpMaxMem}) -> - lamport_clock:init(), + lclock_init(), MemFile = memfile_path(Dir), filelib:ensure_dir(MemFile), @@ -157,11 +158,11 @@ handle_call(Call, From, #state{max_logical_page=unknown} = State) -> handle_call({{write, ClientEpoch, _LogicalPN, _PageBin}, LC1}, _From, #state{min_epoch=MinEpoch} = State) when ClientEpoch < MinEpoch -> - LC2 = lamport_clock:update(LC1), + LC2 = lclock_update(LC1), {reply, {error_badepoch, LC2}, State}; handle_call({{write, _ClientEpoch, LogicalPN, PageBin}, LC1}, _From, #state{max_logical_page=MLPN} = State) -> - LC2 = lamport_clock:update(LC1), + LC2 = lclock_update(LC1), case check_write(LogicalPN, PageBin, State) of {ok, Offset} -> ok = write_page(Offset, LogicalPN, PageBin, State), @@ -176,20 +177,20 @@ handle_call({{write, _ClientEpoch, LogicalPN, PageBin}, LC1}, _From, handle_call({{read, ClientEpoch, _LogicalPN}, LC1}, _From, #state{min_epoch=MinEpoch} = State) when ClientEpoch < MinEpoch -> - LC2 = lamport_clock:update(LC1), + LC2 = lclock_update(LC1), {reply, {error_badepoch, LC2}, State}; handle_call({{read, _ClientEpoch, LogicalPN}, LC1}, _From, State) -> - LC2 = lamport_clock:update(LC1), + LC2 = lclock_update(LC1), Reply = read_page(LogicalPN, State), ?EVENT_LOG({flu, read, self(), LogicalPN, Reply}), {reply, {Reply, LC2}, State}; handle_call({{seal, ClientEpoch}, LC1}, _From, #state{min_epoch=MinEpoch} = State) when ClientEpoch =< MinEpoch -> - LC2 = lamport_clock:update(LC1), + LC2 = lclock_update(LC1), {reply, {error_badepoch, LC2}, State}; handle_call({{seal, ClientEpoch}, LC1}, _From, #state{max_logical_page=MLPN}=State) -> - LC2 = lamport_clock:update(LC1), + LC2 = lclock_update(LC1), NewState = State#state{min_epoch=ClientEpoch}, ok = write_hard_state(NewState), {reply, {{ok, MLPN}, LC2}, NewState}; @@ -197,10 +198,10 @@ handle_call({{seal, ClientEpoch}, LC1}, _From, #state{max_logical_page=MLPN}=Sta handle_call({{trim, ClientEpoch, _LogicalPN}, LC1}, _From, #state{min_epoch=MinEpoch} = State) when ClientEpoch < MinEpoch -> - LC2 = lamport_clock:update(LC1), + LC2 = lclock_update(LC1), {reply, {error_badepoch, LC2}, State}; handle_call({{trim, _ClientEpoch, LogicalPN}, LC1}, _From, State) -> - LC2 = lamport_clock:update(LC1), + LC2 = lclock_update(LC1), {Reply, NewState} = do_trim_or_fill(trim, LogicalPN, State), ?EVENT_LOG({flu, trim, self(), LogicalPN, Reply}), {reply, {Reply, LC2}, NewState}; @@ -208,10 +209,10 @@ handle_call({{trim, _ClientEpoch, LogicalPN}, LC1}, _From, State) -> handle_call({{fill, ClientEpoch, _LogicalPN}, LC1}, _From, #state{min_epoch=MinEpoch} = State) when ClientEpoch < MinEpoch -> - LC2 = lamport_clock:update(LC1), + LC2 = lclock_update(LC1), {reply, {error_badepoch, LC2}, State}; handle_call({{fill, _ClientEpoch, LogicalPN}, LC1}, _From, State) -> - LC2 = lamport_clock:update(LC1), + LC2 = lclock_update(LC1), {Reply, NewState} = do_trim_or_fill(fill, LogicalPN, State), ?EVENT_LOG({flu, fill, self(), LogicalPN, Reply}), {reply, {Reply, LC2}, NewState}; @@ -439,3 +440,27 @@ msc(_From, _To, _Tag) -> msc(_From, _To, _Tag) -> ok. -endif. % PULSE_HACkING + +-ifdef(PULSE). + +lclock_init() -> + lamport_clock:init(). + +lclock_get() -> + lamport_clock:get(). + +lclock_update(LC) -> + lamport_clock:update(LC). + +-else. % PULSE + +lclock_init() -> + ok. + +lclock_get() -> + ok. + +lclock_update(_LC) -> + ok. + +-endif. % PLUSE diff --git a/prototype/corfurl/src/corfurl_sequencer.erl b/prototype/corfurl/src/corfurl_sequencer.erl index 4f14e66..f600713 100644 --- a/prototype/corfurl/src/corfurl_sequencer.erl +++ b/prototype/corfurl/src/corfurl_sequencer.erl @@ -33,6 +33,7 @@ -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). +-compile(export_all). -ifdef(PULSE). -compile({parse_transform, pulse_instrument}). -endif. @@ -50,15 +51,15 @@ stop(Pid) -> gen_server:call(Pid, stop, infinity). get(Pid, NumPages) -> - {LPN, LC} = gen_server:call(Pid, {get, NumPages, lamport_clock:get()}, + {LPN, LC} = gen_server:call(Pid, {get, NumPages, lclock_get()}, infinity), - lamport_clock:update(LC), + lclock_update(LC), LPN. %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% init({FLUs, TypeOrSeed}) -> - lamport_clock:init(), + lclock_init(), MLP = get_max_logical_page(FLUs), if TypeOrSeed == standard -> {ok, MLP + 1}; @@ -69,10 +70,10 @@ init({FLUs, TypeOrSeed}) -> end. handle_call({get, NumPages, LC}, _From, MLP) when is_integer(MLP) -> - NewLC = lamport_clock:update(LC), + NewLC = lclock_update(LC), {reply, {MLP, NewLC}, MLP + NumPages}; handle_call({get, NumPages, LC}, _From, {MLP, BadPercent, MaxDifference}) -> - NewLC = lamport_clock:update(LC), + NewLC = lclock_update(LC), Fudge = case random:uniform(100) of N when N < BadPercent -> random:uniform(MaxDifference * 2) - MaxDifference; @@ -94,7 +95,7 @@ handle_info(_Info, MLP) -> {noreply, MLP}. terminate(_Reason, _MLP) -> - %% io:format(user, "C=~w,", [lamport_clock:get()]), + %% io:format(user, "C=~w,", [lclock_get()]), ok. code_change(_OldVsn, MLP, _Extra) -> @@ -107,51 +108,26 @@ get_max_logical_page(FLUs) -> FLU <- FLUs, {ok, Ps} <- [corfurl_flu:status(FLU)]]). -%%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% +-ifdef(PULSE). --ifdef(TEST). --ifndef(PULSE). +lclock_init() -> + lamport_clock:init(). -smoke_test() -> - BaseDir = "/tmp/" ++ atom_to_list(?MODULE) ++ ".", - PageSize = 8, - NumPages = 500, - NumFLUs = 4, - MyDir = fun(X) -> BaseDir ++ integer_to_list(X) end, - Del = fun() -> [ok = corfurl_util:delete_dir(MyDir(X)) || - X <- lists:seq(1, NumFLUs)] end, +lclock_get() -> + lamport_clock:get(). - Del(), - FLUs = [begin - element(2, corfurl_flu:start_link(MyDir(X), - PageSize, NumPages*PageSize)) - end || X <- lists:seq(1, NumFLUs)], - FLUsNums = lists:zip(FLUs, lists:seq(1, NumFLUs)), - - try - [ok = corfurl_flu:write(FLU, 1, PageNum, <<42:(8*8)>>) || - {FLU, PageNum} <- FLUsNums], - MLP0 = NumFLUs, - NumFLUs = get_max_logical_page(FLUs), +lclock_update(LC) -> + lamport_clock:update(LC). - %% Excellent. Now let's start the sequencer and see if it gets - %% the same answer. If yes, then the first get will return MLP1, - %% yadda yadda. - MLP1 = MLP0 + 1, - MLP3 = MLP0 + 3, - MLP4 = MLP0 + 4, - {ok, Sequencer} = start_link(FLUs), - try - MLP1 = get(Sequencer, 2), - MLP3 = get(Sequencer, 1), - MLP4 = get(Sequencer, 1) - after - stop(Sequencer) - end - after - [ok = corfurl_flu:stop(FLU) || FLU <- FLUs], - Del() - end. +-else. % PULSE --endif. % not PULSE --endif. % TEST +lclock_init() -> + ok. + +lclock_get() -> + ok. + +lclock_update(_LC) -> + ok. + +-endif. % PLUSE diff --git a/prototype/corfurl/test/corfurl_pulse.erl b/prototype/corfurl/test/corfurl_pulse.erl index 0f8eac6..72eb6bd 100644 --- a/prototype/corfurl/test/corfurl_pulse.erl +++ b/prototype/corfurl/test/corfurl_pulse.erl @@ -505,6 +505,8 @@ check_trace(Trace0, _Cmds, _Seed) -> ?QC_FMT("*Trace: ~p\n", [Trace]), ?QC_FMT("*ModsReads: ~p\n", [eqc_temporal:unions([Mods,Reads])]), ?QC_FMT("*InvalidTtns: ~p\n", [InvalidTransitions]), + ?QC_FMT("*ValuesR: ~p\n", [eqc_temporal:unions([ValuesR, StartsDones])]), + ?QC_FMT("*Calls: ~p\n", [Calls]), ?QC_FMT("*BadReads: ~p\n", [BadReads]) end, conjunction( diff --git a/prototype/corfurl/test/corfurl_sequencer_test.erl b/prototype/corfurl/test/corfurl_sequencer_test.erl new file mode 100644 index 0000000..0bef793 --- /dev/null +++ b/prototype/corfurl/test/corfurl_sequencer_test.erl @@ -0,0 +1,80 @@ +%% ------------------------------------------------------------------- +%% +%% Copyright (c) 2014 Basho Technologies, Inc. All Rights Reserved. +%% +%% This file is provided to you under the Apache License, +%% Version 2.0 (the "License"); you may not use this file +%% except in compliance with the License. You may obtain +%% a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, +%% software distributed under the License is distributed on an +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +%% KIND, either express or implied. See the License for the +%% specific language governing permissions and limitations +%% under the License. +%% +%% ------------------------------------------------------------------- + +-module(corfurl_sequencer_test). + +-compile(export_all). + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). +-compile(export_all). +-ifdef(PULSE). +-compile({parse_transform, pulse_instrument}). +-endif. +-endif. + +-define(M, corfurl_sequencer). + +-ifdef(TEST). +-ifndef(PULSE). + +smoke_test() -> + BaseDir = "/tmp/" ++ atom_to_list(?MODULE) ++ ".", + PageSize = 8, + NumPages = 500, + NumFLUs = 4, + 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)], + FLUsNums = lists:zip(FLUs, lists:seq(1, NumFLUs)), + + try + [ok = corfurl_flu:write(FLU, 1, PageNum, <<42:(8*8)>>) || + {FLU, PageNum} <- FLUsNums], + MLP0 = NumFLUs, + NumFLUs = ?M:get_max_logical_page(FLUs), + + %% Excellent. Now let's start the sequencer and see if it gets + %% the same answer. If yes, then the first get will return MLP1, + %% yadda yadda. + MLP1 = MLP0 + 1, + MLP3 = MLP0 + 3, + MLP4 = MLP0 + 4, + {ok, Sequencer} = ?M:start_link(FLUs), + try + MLP1 = ?M:get(Sequencer, 2), + MLP3 = ?M:get(Sequencer, 1), + MLP4 = ?M:get(Sequencer, 1) + after + ?M:stop(Sequencer) + end + after + [ok = corfurl_flu:stop(FLU) || FLU <- FLUs], + Del() + end. + +-endif. % not PULSE +-endif. % TEST diff --git a/prototype/corfurl/test/corfurl_test.erl b/prototype/corfurl/test/corfurl_test.erl index 1cf12e0..c745538 100644 --- a/prototype/corfurl/test/corfurl_test.erl +++ b/prototype/corfurl/test/corfurl_test.erl @@ -106,7 +106,7 @@ smoke1_test() -> %% Simulate a failed write to the chain. [F6a, F6b, F6c] = Chain6 = ?M:project_to_chain(6, P1), NotHead6 = [F6b, F6c], - ok = ?M:write_single_page_to_chain([F6a], Epoch, 6, Pg6, 1), + ok = ?M:write_single_page_to_chain([F6a], [F6a], Epoch, 6, Pg6, 1), %% Does the chain look as expected? {ok, Pg6} = corfurl_flu:read(?M:flu_pid(F6a), Epoch, 6),