Skip to content

Commit

Permalink
test: fix race condition in ar_mining_stats
Browse files Browse the repository at this point in the history
Make pause_performance_reports a call instead of a cast to
avoid a rare situation where the test proceeds before the
reports are paused
  • Loading branch information
JamesPiechota committed Dec 26, 2024
1 parent 0716234 commit 0b9b69b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions apps/arweave/src/ar_mining_stats.erl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ start_performance_reports() ->

%% @doc Stop logging performance reports for the given number of milliseconds.
pause_performance_reports(Time) ->
gen_server:cast(?MODULE, {pause_performance_reports, Time}).
gen_server:call(?MODULE, {pause_performance_reports, Time}).

vdf_computed() ->
increment_count(vdf).
Expand Down Expand Up @@ -207,6 +207,12 @@ mining_paused() ->
init([]) ->
{ok, #state{}}.

handle_call({pause_performance_reports, Time}, _From, State) ->
Now = os:system_time(millisecond),
Timeout = Now + Time,
{reply, ok, State#state{ pause_performance_reports = true,
pause_performance_reports_timeout = Timeout }};

handle_call(Request, _From, State) ->
?LOG_WARNING([{event, unhandled_call}, {module, ?MODULE}, {request, Request}]),
{reply, ok, State}.
Expand All @@ -227,11 +233,7 @@ handle_cast(report_performance, State) ->
ar_util:cast_after(?PERFORMANCE_REPORT_FREQUENCY_MS, ?MODULE, report_performance),
{noreply, State};

handle_cast({pause_performance_reports, Time}, State) ->
Now = os:system_time(millisecond),
Timeout = Now + Time,
{noreply, State#state{ pause_performance_reports = true,
pause_performance_reports_timeout = Timeout }};


handle_cast(Cast, State) ->
?LOG_WARNING([{event, unhandled_cast}, {module, ?MODULE}, {cast, Cast}]),
Expand Down

0 comments on commit 0b9b69b

Please sign in to comment.