Skip to content

Commit b7b165f

Browse files
committed
Update existing tests for new tag structure
1 parent 3170884 commit b7b165f

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

packages/sync-service/test/electric/plug/router_test.exs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,13 +2789,27 @@ defmodule Electric.Plug.RouterTest do
27892789
task = live_shape_req(req, ctx.opts)
27902790
Postgrex.query!(ctx.db_conn, "UPDATE parent SET other_value = 10 WHERE id = 2")
27912791

2792-
tag =
2792+
# With DNF, WHERE clause `subquery AND field_condition` creates one disjunct with two positions:
2793+
# - Position 0: value IN (SELECT ...) - references `value` column
2794+
# - Position 1: other_value >= $1 - references `other_value` column
2795+
# Tags include both positions concatenated with `/`.
2796+
# Row id=3 has value=20, other_value=20
2797+
tag_value =
2798+
:crypto.hash(:md5, ctx.stack_id <> req.handle <> "v:20")
2799+
|> Base.encode16(case: :lower)
2800+
2801+
tag_other_value =
27932802
:crypto.hash(:md5, ctx.stack_id <> req.handle <> "v:20")
27942803
|> Base.encode16(case: :lower)
27952804

2805+
tag = tag_value <> "/" <> tag_other_value
2806+
27962807
assert {_, 200,
27972808
[
2798-
%{"headers" => %{"tags" => [^tag]}, "value" => %{"id" => "3"}},
2809+
%{
2810+
"headers" => %{"tags" => [^tag], "active_conditions" => [true, true]},
2811+
"value" => %{"id" => "3"}
2812+
},
27992813
%{"headers" => %{"control" => "snapshot-end"}},
28002814
up_to_date_ctl()
28012815
]} =
@@ -2820,11 +2834,24 @@ defmodule Electric.Plug.RouterTest do
28202834
# Should contain the data record and the snapshot-end control message
28212835
assert length(response) == 2
28222836

2823-
tag = :crypto.hash(:md5, ctx.stack_id <> req.handle <> "v:1") |> Base.encode16(case: :lower)
2837+
# With DNF, WHERE clause `subquery AND field_condition` creates one disjunct with two positions:
2838+
# - Position 0: "parentId" IN (SELECT ...) - references `parentId` column
2839+
# - Position 1: "Value" >= $1 - references `Value` column
2840+
# Tags include both positions concatenated with `/`.
2841+
# Row id=1 has parentId=1, Value=10
2842+
tag_parent_id =
2843+
:crypto.hash(:md5, ctx.stack_id <> req.handle <> "v:1")
2844+
|> Base.encode16(case: :lower)
2845+
2846+
tag_value =
2847+
:crypto.hash(:md5, ctx.stack_id <> req.handle <> "v:10")
2848+
|> Base.encode16(case: :lower)
2849+
2850+
tag = tag_parent_id <> "/" <> tag_value
28242851

28252852
assert %{
28262853
"value" => %{"id" => "1", "parentId" => "1", "Value" => "10"},
2827-
"headers" => %{"tags" => [^tag]}
2854+
"headers" => %{"tags" => [^tag], "active_conditions" => [true, true]}
28282855
} =
28292856
Enum.find(response, &Map.has_key?(&1, "key"))
28302857

packages/sync-service/test/electric/shapes/querying_test.exs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,25 @@ defmodule Electric.Shapes.QueryingTest do
347347
Querying.stream_initial_data(conn, "dummy-stack-id", "dummy-shape-handle", shape)
348348
)
349349

350+
# With DNF decomposition, OR creates two disjuncts:
351+
# - Disjunct 1: parent_id IN (SELECT ...) - position 0
352+
# - Disjunct 2: parent_id IS NULL - position 1
353+
# Both disjuncts reference parent_id, so each row gets two tags (one per disjunct)
354+
# with the same hash value (since same column).
355+
# active_conditions tracks truth value at each position.
350356
assert [
351-
%{value: %{value: "10", parent_id: "1"}, headers: %{tags: [^tag1]}},
352-
%{value: %{value: "20", parent_id: nil}, headers: %{tags: [^tag_null]}},
353-
%{value: %{value: "30", parent_id: "2"}, headers: %{tags: [^tag2]}}
357+
%{
358+
value: %{value: "10", parent_id: "1"},
359+
headers: %{tags: [^tag1, ^tag1], active_conditions: [true, true]}
360+
},
361+
%{
362+
value: %{value: "20", parent_id: nil},
363+
headers: %{tags: [^tag_null, ^tag_null], active_conditions: [nil, true]}
364+
},
365+
%{
366+
value: %{value: "30", parent_id: "2"},
367+
headers: %{tags: [^tag2, ^tag2], active_conditions: [true, true]}
368+
}
354369
] = result
355370
end
356371

0 commit comments

Comments
 (0)