-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing rework:
.ToObservableChangeSet()
(#760)
* Rebuilt test fixtures for both `.ToObservableChangeSet()` operators, increasting code coverage from 69% to 100% across the internal implementation classes. Identified existing defects within the `.ToObservableChangeSet()` operators, mostly related to error and completion propagation, and implemented testing for this behavior, with the tests being marked as "Skip" until the defects are fixed. This also includes the defect referred in #635. Added an `IsCompleted` flag to `ChangeSetAggregator<T>`, to allow for testing of completion propagation. * Added benchmarks for `.ToObservableChangeSet()` operators.
- Loading branch information
1 parent
d647e33
commit fd9083f
Showing
8 changed files
with
642 additions
and
47 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/DynamicData.Benchmarks/Cache/ToObservableChangeSet_Cache.cs
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,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reactive.Subjects; | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Columns; | ||
|
||
namespace DynamicData.Benchmarks.Cache; | ||
|
||
[MemoryDiagnoser] | ||
[MarkdownExporterAttribute.GitHub] | ||
[HideColumns(Column.Ratio, Column.RatioSD, Column.AllocRatio)] | ||
public class ToObservableChangeSet_Cache | ||
{ | ||
public const int RngSeed | ||
= 1234567; | ||
|
||
public const int MaxItemCount | ||
= 1000; | ||
|
||
static ToObservableChangeSet_Cache() | ||
{ | ||
_items = Enumerable.Range(1, MaxItemCount / 2) | ||
.Select(id => new Item() { Id = id }) | ||
.ToArray(); | ||
|
||
var rng = new Random(RngSeed); | ||
|
||
_itemIndexSequence = Enumerable.Range(1, MaxItemCount) | ||
.Select(_ => rng.Next(maxValue: _items.Count)) | ||
.ToArray(); | ||
} | ||
|
||
[Benchmark] | ||
[Arguments(0, -1)] | ||
[Arguments(0, 0)] | ||
[Arguments(0, 1)] | ||
[Arguments(1, 1)] | ||
[Arguments(10, -1)] | ||
[Arguments(10, 1)] | ||
[Arguments(10, 5)] | ||
[Arguments(10, 10)] | ||
[Arguments(100, -1)] | ||
[Arguments(100, 10)] | ||
[Arguments(100, 50)] | ||
[Arguments(100, 100)] | ||
[Arguments(1_000, -1)] | ||
[Arguments(1_000, 100)] | ||
[Arguments(1_000, 500)] | ||
[Arguments(1_000, 1_000)] | ||
public void AddsUpdatesAndFinalization(int itemCount, int sizeLimit) | ||
{ | ||
using var source = new Subject<Item>(); | ||
|
||
using var subscription = source | ||
.ToObservableChangeSet( | ||
keySelector: item => item.Id, | ||
limitSizeTo: sizeLimit) | ||
.Subscribe(); | ||
|
||
var indexModulus = (itemCount / 2) + 1; | ||
for(var i = 0; i < itemCount; ++i) | ||
source.OnNext(_items[_itemIndexSequence[i] % indexModulus]); | ||
source.OnCompleted(); | ||
} | ||
|
||
public class Item | ||
{ | ||
public int Id { get; init; } | ||
} | ||
|
||
private static readonly IReadOnlyList<Item> _items; | ||
private static readonly IReadOnlyList<int> _itemIndexSequence; | ||
} |
44 changes: 44 additions & 0 deletions
44
src/DynamicData.Benchmarks/List/ToObservableChangeSet_List.cs
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,44 @@ | ||
using System; | ||
using System.Reactive.Subjects; | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Columns; | ||
|
||
namespace DynamicData.Benchmarks.List; | ||
|
||
[MemoryDiagnoser] | ||
[MarkdownExporterAttribute.GitHub] | ||
[HideColumns(Column.Ratio, Column.RatioSD, Column.AllocRatio)] | ||
public class ToObservableChangeSet_List | ||
{ | ||
[Benchmark] | ||
[Arguments(0, -1)] | ||
[Arguments(0, 0)] | ||
[Arguments(0, 1)] | ||
[Arguments(1, 1)] | ||
[Arguments(10, -1)] | ||
[Arguments(10, 1)] | ||
[Arguments(10, 5)] | ||
[Arguments(10, 10)] | ||
[Arguments(100, -1)] | ||
[Arguments(100, 10)] | ||
[Arguments(100, 50)] | ||
[Arguments(100, 100)] | ||
[Arguments(1_000, -1)] | ||
[Arguments(1_000, 100)] | ||
[Arguments(1_000, 500)] | ||
[Arguments(1_000, 1_000)] | ||
public void AddsUpdatesAndFinalization(int itemCount, int sizeLimit) | ||
{ | ||
using var source = new Subject<int>(); | ||
|
||
using var subscription = source | ||
.ToObservableChangeSet(limitSizeTo: sizeLimit) | ||
.Subscribe(); | ||
|
||
var indexModulus = (itemCount / 2) + 1; | ||
for(var i = 0; i < itemCount; ++i) | ||
source.OnNext(i); | ||
source.OnCompleted(); | ||
} | ||
} |
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
Oops, something went wrong.