Skip to content

Conversation

@dennisdoomen
Copy link
Member

@dennisdoomen dennisdoomen commented May 1, 2020

  • Event constraining extensions WithArgs and WithSender will return only the events that match the constraints
  • Several event raising assertion APIs will return an IEventRecording instead of IEventRecorder
  • The classes EventMonitor and RecordedEvent are now treated as internal code
  • Renamed method GetEventRecorder of interface IMonitor to GetRecordingFor and will return IEventRecording

Fixes #337

@dennisdoomen dennisdoomen marked this pull request as ready for review May 1, 2020 19:50
@dennisdoomen dennisdoomen requested a review from jnyrup May 1, 2020 19:50

public IEnumerator<OccurredEvent> GetEnumerator()
{
foreach (RecordedEvent @event in raisedEvents.ToArray())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a lock around raisedEvent.ToArray()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because it's a BlockingCollection. Wondering if I should change the name of field to make that clearer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm asking since the OccurredEvents property is iterating the collection inside a lock.

Peeking in the source it seems that both GetEnumerator() and ToArray() on a BlockingCollection forwards the calls to the underlying ConcurrentQueue.

https://source.dot.net/#System.Private.CoreLib/ConcurrentQueue.cs,ceb5564a9e120593,references
https://source.dot.net/#System.Private.CoreLib/ConcurrentQueue.cs,956829c6ddc21632,references

From ConcurrentQueue.GetEnumerator

The enumerator is safe to use concurrently with reads from and writes to the queue

To summarize, as I read the documentation neither calls to GetEnumerator() nor ToArray() needs to be surrounded by a lock.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

@dennisdoomen dennisdoomen force-pushed the Fix/337 branch 2 times, most recently from 932a7a0 to f112c03 Compare May 2, 2020 18:49
@dennisdoomen dennisdoomen requested a review from jnyrup May 2, 2020 18:51
Copy link
Member

@jnyrup jnyrup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work 👍
(Also gave me a reason to get a better grasp of this part of FA)

…ching events

* Several event raising assertion APIs will return an `IEventRecording` instead of `IEventRecorder`
* The classes `EventMonitor` and `RecordedEvent` are now treated as `internal` code
* Renamed method `GetEventRecorder` of interface `IMonitor` to `GetRecordingFor` and will return `IEventRecording`
@dennisdoomen dennisdoomen merged commit b8d6ac2 into fluentassertions:develop May 3, 2020
@dennisdoomen dennisdoomen deleted the Fix/337 branch May 3, 2020 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IEventRecorder .WithArgs<T> returns unfiltered IEventRecorder - feature / room for improvement?

2 participants