Skip to content

Commit bfa34ce

Browse files
chore(spec): clean up fellowship sediment + isolate races per run
Two-pronged fix for the shared-app data leak that pollutes client_spec queries: 1. Active cleanup in before(:all): query_users by the four well-known fellowship names (Frodo / Sam / Gandalf / Legolas) and hard-delete any leftovers from prior runs whose after(:all) didn't fire. delete_users is idempotent, so this is safe to re-run. 2. Per-run unique race tag (e.g. 'Hobbit-aBcD1234') so the queries-users test stays isolated from concurrent runs and from the sliver between the cleanup above and the new upserts. The active-cleanup half stops the sediment from growing forever — the random-tag-only patch (prior attempt) inserts new users with new tags every run, so the shared app keeps accumulating users indefinitely. Per-PR scratch app via create_app is still the right long-term fix and is tracked separately.
1 parent 0d2214b commit bfa34ce

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

spec/client_spec.rb

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,39 @@ def loop_times(times)
2525

2626
@created_users = []
2727

28+
# Active cleanup: hard-delete fellowship leftovers from prior CI runs whose
29+
# after(:all) didn't fire. delete_users is idempotent — safe whether or not
30+
# the previous run cleaned up. Without this the shared test app accumulates
31+
# Frodos / Sams / Gandalfs / Legolases forever and other tests that query
32+
# users by name end up matching sediment.
33+
begin
34+
leftover = @client.query_users(
35+
{ 'name' => { '$in' => ['Frodo Baggins', 'Samwise Gamgee',
36+
'Gandalf the Grey', 'Legolas'] } }
37+
)
38+
leftover_ids = leftover['users'].map { |u| u['id'] }
39+
if leftover_ids.any?
40+
@client.delete_users(leftover_ids,
41+
user: StreamChat::HARD_DELETE,
42+
messages: StreamChat::HARD_DELETE)
43+
end
44+
rescue StandardError
45+
# Best-effort: a failed cleanup must not block tests; concurrent-run
46+
# protection below handles the residual case.
47+
end
48+
49+
# Per-run race markers so concurrent CI runs (and the seconds-window between
50+
# the active cleanup above and the upserts below) don't collide on
51+
# race=Hobbit / Elf / Istari lookups.
52+
@hobbit_race = "Hobbit-#{SecureRandom.alphanumeric(8)}"
53+
@elf_race = "Elf-#{SecureRandom.alphanumeric(8)}"
54+
@istari_race = "Istari-#{SecureRandom.alphanumeric(8)}"
55+
2856
@fellowship_of_the_ring = [
29-
{ id: SecureRandom.uuid, name: 'Frodo Baggins', race: 'Hobbit', age: 50 },
30-
{ id: SecureRandom.uuid, name: 'Samwise Gamgee', race: 'Hobbit', age: 38 },
31-
{ id: SecureRandom.uuid, name: 'Gandalf the Grey', race: 'Istari' },
32-
{ id: SecureRandom.uuid, name: 'Legolas', race: 'Elf', age: 500 }
57+
{ id: SecureRandom.uuid, name: 'Frodo Baggins', race: @hobbit_race, age: 50 },
58+
{ id: SecureRandom.uuid, name: 'Samwise Gamgee', race: @hobbit_race, age: 38 },
59+
{ id: SecureRandom.uuid, name: 'Gandalf the Grey', race: @istari_race },
60+
{ id: SecureRandom.uuid, name: 'Legolas', race: @elf_race, age: 500 }
3361
]
3462

3563
@legolas = @fellowship_of_the_ring[3][:id]
@@ -588,7 +616,7 @@ def loop_times(times)
588616
end
589617

590618
it 'queries users' do
591-
response = @client.query_users({ 'race' => { '$eq' => 'Hobbit' } }, sort: { 'age' => -1 })
619+
response = @client.query_users({ 'race' => { '$eq' => @hobbit_race } }, sort: { 'age' => -1 })
592620
expect(response['users'].length).to eq 2
593621
expect([50, 38]).to eq(response['users'].map { |u| u['age'] })
594622
end

0 commit comments

Comments
 (0)