The When_unsubscribing_to_scaled_out_publisher has a race condition. It tests if an unsubscribe message is sent to all instances of scaled-out endpoint. This is done via shared stated stored in test context.
This results in race condition as a List<string> type is potentially modified concurrently by two threads (two publishers).
This results in test failing in at least two ways:
Both behaviors can be explained looking at List<string>.Add(string item) implementation:
C#
public void Add(T item)
{
if (this._size == this._items.Length)
this.EnsureCapacity(this._size + 1);
this._items[this._size++] = item;
++this._version;
}
The first problem happens when two both threads increase index before any of them writes to location at index. The second is probably caused by two threads reading cached value of index and ending up writing to location at 0.
yeah, a threadsafe collection should be used instead. Marking this as an easy candidate for the next release.
also we should fix this in When_subscribing_to_scaled_out_publisher as well.
Most helpful comment
yeah, a threadsafe collection should be used instead. Marking this as an easy candidate for the next release.