Skip to content

Commit

Permalink
Testing rework: .ToObservableChangeSet() (#760)
Browse files Browse the repository at this point in the history
* 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
JakenVeina authored Nov 20, 2023
1 parent d647e33 commit fd9083f
Show file tree
Hide file tree
Showing 8 changed files with 642 additions and 47 deletions.
75 changes: 75 additions & 0 deletions src/DynamicData.Benchmarks/Cache/ToObservableChangeSet_Cache.cs
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 src/DynamicData.Benchmarks/List/ToObservableChangeSet_List.cs
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2638,6 +2638,7 @@ namespace DynamicData.Tests
public ChangeSetAggregator(System.IObservable<DynamicData.IChangeSet<TObject>> source) { }
public DynamicData.IObservableList<TObject> Data { get; }
public System.Exception? Exception { get; set; }
public bool IsCompleted { get; }
public System.Collections.Generic.IList<DynamicData.IChangeSet<TObject>> Messages { get; }
public void Dispose() { }
protected virtual void Dispose(bool isDisposing) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2638,6 +2638,7 @@ namespace DynamicData.Tests
public ChangeSetAggregator(System.IObservable<DynamicData.IChangeSet<TObject>> source) { }
public DynamicData.IObservableList<TObject> Data { get; }
public System.Exception? Exception { get; set; }
public bool IsCompleted { get; }
public System.Collections.Generic.IList<DynamicData.IChangeSet<TObject>> Messages { get; }
public void Dispose() { }
protected virtual void Dispose(bool isDisposing) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2638,6 +2638,7 @@ namespace DynamicData.Tests
public ChangeSetAggregator(System.IObservable<DynamicData.IChangeSet<TObject>> source) { }
public DynamicData.IObservableList<TObject> Data { get; }
public System.Exception? Exception { get; set; }
public bool IsCompleted { get; }
public System.Collections.Generic.IList<DynamicData.IChangeSet<TObject>> Messages { get; }
public void Dispose() { }
protected virtual void Dispose(bool isDisposing) { }
Expand Down
Loading

0 comments on commit fd9083f

Please sign in to comment.