-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: rerun failed task and fix processing state (#848)
* fix: rerun failed task and fix processing state * fix: demand only when doesn't rerun
- Loading branch information
Showing
7 changed files
with
129 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
defmodule AeMdw.Sync.AsyncTasks.ConsumerTest do | ||
use ExUnit.Case | ||
|
||
alias AeMdw.AsyncTaskTestUtil | ||
alias AeMdw.Db.Aex9BalancesCache | ||
alias AeMdw.Db.Model | ||
alias AeMdw.Sync.AsyncTasks | ||
|
||
import Mock | ||
|
||
require Model | ||
|
||
test "enqueue and dequeue with failed task" do | ||
contract_pk = :crypto.strong_rand_bytes(32) | ||
{kbi, mbi} = block_index = {543_210, 10} | ||
kb_hash = :crypto.strong_rand_bytes(32) | ||
next_mb_hash = :crypto.strong_rand_bytes(32) | ||
|
||
Aex9BalancesCache.put(contract_pk, block_index, next_mb_hash, %{ | ||
{:address, :crypto.strong_rand_bytes(32)} => <<>> | ||
}) | ||
|
||
with_mocks [ | ||
{AeMdw.Node.Db, [], | ||
[ | ||
get_key_block_hash: fn height -> | ||
assert height == kbi + 1 | ||
Process.sleep(1_000) | ||
kb_hash | ||
end, | ||
get_next_hash: fn ^kb_hash, ^mbi -> next_mb_hash end | ||
]} | ||
] do | ||
AsyncTasks.Supervisor.start_link([]) | ||
|
||
AsyncTasks.Producer.enqueue( | ||
:update_aex9_state, | ||
[contract_pk], | ||
[ | ||
block_index, | ||
Enum.random(1_000_000..99_000_000) | ||
], | ||
only_new: true | ||
) | ||
|
||
consumer_pid = AsyncTaskTestUtil.wakeup_consumer() | ||
|
||
task_pid1 = | ||
Enum.reduce_while(1..100, nil, fn _i, _acc -> | ||
Process.sleep(10) | ||
|
||
case :sys.get_state(consumer_pid) do | ||
%{task: %Task{pid: task_pid}} -> {:halt, task_pid} | ||
_no_task -> {:cont, nil} | ||
end | ||
end) | ||
|
||
Process.exit(task_pid1, :kill) | ||
|
||
assert Enum.any?(1..100, fn _i -> | ||
case :sys.get_state(consumer_pid) do | ||
%{task: %Task{pid: task_pid2}} -> task_pid2 != task_pid1 | ||
_no_task -> false | ||
end | ||
end) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters