Skip to content

Commit 87edfa9

Browse files
dwcullopDarrin Cullop
andauthored
Make SizeLimit tests deterministic by deduplicating generator output (reactivemarbles#1098)
RandomPersonGenerator emits Person rows drawn from a finite name pool (~21 girls + ~30 boys cross-joined with 24 lastnames squared). Person.Key is Person.Name, so two independent .Take(10) calls can produce overlapping keys with non-trivial probability. When they collide, the second batch's AddOrUpdate produces 9 Adds + 1 Update instead of 10 Adds, breaking the per-message assertions in: - InvokeLimitSizeToWhenOverLimit - AddMoreThanLimitInBatched Both tests now draw 60 candidates up front, dedupe by Key, take the first 20, and split into two non-overlapping batches of 10. Verified: 50/50 consecutive runs of SizeLimitFixture pass with no failures. Co-authored-by: Darrin Cullop <dacullop@microsoft.com>
1 parent 8033135 commit 87edfa9

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/DynamicData.Tests/Cache/SizeLimitFixture.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ public void AddMoreThanLimit()
7272
[Fact]
7373
public void AddMoreThanLimitInBatched()
7474
{
75-
_source.AddOrUpdate(_generator.Take(10).ToArray());
76-
_source.AddOrUpdate(_generator.Take(10).ToArray());
75+
// _generator.Take(N) draws random Person rows from a finite name pool; a second
76+
// Take(10) call can produce keys that collide with the first batch, turning an
77+
// Add into an Update and breaking the per-message Adds count. Draw a larger pool
78+
// up front, dedupe by Key, then split into two non-overlapping batches of 10.
79+
var people = _generator.Take(60).DistinctBy(p => p.Key).Take(20).ToArray();
80+
_source.AddOrUpdate(people.Take(10).ToArray());
81+
_source.AddOrUpdate(people.Skip(10).Take(10).ToArray());
7782

7883
_scheduler.Start();
7984

@@ -96,12 +101,17 @@ public void InvokeLimitSizeToWhenOverLimit()
96101
var removesTriggered = false;
97102
var subscriber = _source.LimitSizeTo(10, _scheduler).Subscribe(removes => { removesTriggered = true; });
98103

99-
_source.AddOrUpdate(_generator.Take(10).ToArray());
104+
// _generator.Take(N) draws random Person rows from a finite name pool; a second
105+
// Take(10) call can produce keys that collide with the first batch, turning an
106+
// Add into an Update and breaking the per-message Adds count. Draw a larger pool
107+
// up front, dedupe by Key, then split into two non-overlapping batches of 10.
108+
var people = _generator.Take(60).DistinctBy(p => p.Key).Take(20).ToArray();
109+
_source.AddOrUpdate(people.Take(10).ToArray());
100110
_scheduler.AdvanceBy(TimeSpan.FromMilliseconds(150).Ticks);
101111

102112
removesTriggered.Should().BeFalse();
103113

104-
_source.AddOrUpdate(_generator.Take(10).ToArray());
114+
_source.AddOrUpdate(people.Skip(10).Take(10).ToArray());
105115

106116
_scheduler.AdvanceBy(TimeSpan.FromMilliseconds(150).Ticks);
107117

0 commit comments

Comments
 (0)