Skip to content

Commit

Permalink
Refactor parcels_test.exs
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmi committed Jan 10, 2024
1 parent dbede39 commit 809ce08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- restart strategy
- renamer can be just a simple module
- tick source with timeout
30 changes: 16 additions & 14 deletions test/examples/parcels/parcels_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Strom.Examples.ParcelsTest do
use ExUnit.Case
@moduletag timeout: :infinity

defmodule GenData do
use Strom.DSL
Expand Down Expand Up @@ -76,25 +77,25 @@ defmodule Strom.Examples.ParcelsTest do

def build_order(event) do
list = String.split(event, ",")
type = Enum.at(list, 0)
{:ok, occurred_at, _} = DateTime.from_iso8601(Enum.at(list, 1))
order_number = String.to_integer(Enum.at(list, 2))

%{
type: type,
type: Enum.at(list, 0),
occurred_at: occurred_at,
order_number: order_number,
order_number: String.to_integer(Enum.at(list, 2)),
to_ship: String.to_integer(Enum.at(list, 3))
}
end

def build_parcel(event) do
list = String.split(event, ",")
type = Enum.at(list, 0)
{:ok, occurred_at, _} = DateTime.from_iso8601(Enum.at(list, 1))
order_number = String.to_integer(Enum.at(list, 2))

%{type: type, occurred_at: occurred_at, order_number: order_number}
%{
type: Enum.at(list, 0),
occurred_at: occurred_at,
order_number: String.to_integer(Enum.at(list, 2))
}
end

def force_order(event, memo) do
Expand Down Expand Up @@ -210,16 +211,15 @@ defmodule Strom.Examples.ParcelsTest do
end
end

def generate_data(parcels_count) do
@parcels_count 1_000

test "generate_data" do
GenData.start()
GenData.call(%{stream: List.duplicate(:tick, parcels_count)})
GenData.call(%{stream: List.duplicate(:tick, @parcels_count)})
GenData.stop()
end

test "flow" do
parcels_count = 1_000
generate_data(parcels_count)

test "solve" do
ParcelsFlow.start()
ParcelsFlow.call(%{})

Expand All @@ -237,6 +237,8 @@ defmodule Strom.Examples.ParcelsTest do
|> length()
|> then(&(&1 - 1))

assert shipped_length + threshold_length == parcels_count
assert shipped_length + threshold_length == @parcels_count

ParcelsFlow.stop()
end
end

0 comments on commit 809ce08

Please sign in to comment.