Are substitutes thread-safe?

33 views
Skip to first unread message

Roberto Abreu

unread,
Aug 15, 2018, 4:28:07 PM8/15/18
to NSubstitute
If two different threads call the same substitute method at the exact same time, is it always guaranteed that the actual number of calls will always be correct (in this case, 2)?

David Tchepak

unread,
Aug 15, 2018, 7:04:27 PM8/15/18
to nsubs...@googlegroups.com
Hi Roberto,
I don't think I would ever make a guarantee with regards to anything involving threading! :)

For this case, NSubstitute does use concurrent collections to manage recording these calls, so assuming both calls have completed before your test asserts on the number of calls, it should correctly report two calls.

Regards,
David

On Thu, Aug 16, 2018 at 6:28 AM Roberto Abreu <rca...@gmail.com> wrote:
If two different threads call the same substitute method at the exact same time, is it always guaranteed that the actual number of calls will always be correct (in this case, 2)?

--
You received this message because you are subscribed to the Google Groups "NSubstitute" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nsubstitute...@googlegroups.com.
To post to this group, send email to nsubs...@googlegroups.com.
Visit this group at https://groups.google.com/group/nsubstitute.
For more options, visit https://groups.google.com/d/optout.

Roberto Abreu

unread,
Aug 16, 2018, 10:09:50 AM8/16/18
to NSubstitute
Haha!

Ok, thank you very much for the information!

Best,
Roberto
Reply all
Reply to author
Forward
0 new messages