Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Concurrent logging causes "Collection was modified" error #75

Closed
mhgames opened this issue Jul 20, 2017 · 3 comments
Closed

Concurrent logging causes "Collection was modified" error #75

mhgames opened this issue Jul 20, 2017 · 3 comments
Labels

Comments

@mhgames
Copy link

mhgames commented Jul 20, 2017

I've never had issues with Java implementation of ExtentReports (version 2.4) running Selenium tests in parallel in the past.

But currently I'm running some API tests on C# implementation of ExtentReports in parallel and these tests are very fast, so when I'm calling .Log(...) on ExtentTest, I end up (from time to time) with System.InvalidOperationException (Collection was modified; enumeration operation may not execute.)

Here's part of the stacktrace:
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List1.ForEach(Action1 action)
at AventStack.ExtentReports.Model.Test.UpdateTestStatusRecursive(Test test)
at AventStack.ExtentReports.Model.Test.End()
at AventStack.ExtentReports.Model.Test.<>c.b__73_0(Test x)
at System.Collections.Generic.List1.ForEach(Action1 action)
at AventStack.ExtentReports.Model.Test.EndChildTestsRecursive(Test test)
at AventStack.ExtentReports.Model.Test.End()
at AventStack.ExtentReports.Model.Report.EndTest(Test test)
at AventStack.ExtentReports.Model.Report.b__19_0(Test test)
at System.Collections.Generic.List1.ForEach(Action1 action)
at AventStack.ExtentReports.Model.Report.CollectRunInfo()
at AventStack.ExtentReports.Model.Report.AddLog(Test test, Log log)
at AventStack.ExtentReports.ExtentTest.AddLog(Log evt)
at AventStack.ExtentReports.ExtentTest.Log(Status status, String details, MediaEntityModelProvider provider)

Since it's an error on System.Collections.Generic.List, it could imho be solved in your AbstractStructure.cs file with ConcurrentDictionary instead of List _list, with integer TKey as array index and TValue as array value, since there's no ConcurrentList in C# yet and ConcurrentBag is unordered.

@mhgames
Copy link
Author

mhgames commented Aug 1, 2017

I'm currently using locks to get rid of this message, but apparently the more tests I have, the slower the run is, since the ForEach takes longer and longer.

@anshooarora anshooarora added the bug label Aug 9, 2017
@anshooarora
Copy link
Owner

anshooarora commented Aug 10, 2017

Can you please try with the attached dll. Any luck?

ExtentReports.zip

@mhgames
Copy link
Author

mhgames commented Aug 11, 2017

I removed all the locks and it works, no error. Also the profiler no longer says that ExtentReports are causing performance issues. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants