Noksa / Allure.NUnit

C# NUnit Allure with improvements and SpecFlow3 adapter
MIT License
18 stars 6 forks source link

Produce Step from the child thread #48

Open devAarno opened 4 years ago

devAarno commented 4 years ago

Story My test has a long-time item creation part, but I can speed-up it by parallelism. The item builder writes an Allure report. Also, I have noticed that the parallel item building may fail sometimes, but I can not get the report because of the inner exception in your library.

Example

namespace ...
{
    [TestFixture(Description = "Smoke tests")]
    public class GroupDeleteEntities : AllureReport
    {
        [Test]
        [Category(TestGroups.Smoke)]
        [Category(TestGroups.MSSQL)]
        [AllureTag(TestGroups.Smoke, TestGroups.MSSQL)]
        [AllureSeverity(SeverityLevel.Critical)]
        public void CreateAndDeleteManyItems()
        {
            Parallel.For(0, 1000, new ParallelOptions {MaxDegreeOfParallelism = 8, TaskScheduler = TaskScheduler.Default}, i =>
            {
                AllureLifecycle.Instance.RunStep("Step", () => { /* long Selenium / Rest-Api requests */ });
            });
        }
    }
}

produces

XXXXX.Tests.Tests.Smoke.GroupDelete.GroupDeleteEntities.CreateAndDeleteManyItems

System.AggregateException : One or more errors occurred. (Value cannot be null. (Parameter 'key')) (Value cannot be null. (Parameter 'key')) (Value ca...

System.AggregateException : One or more errors occurred. (Value cannot be null. (Parameter 'key')) (Value cannot be null. (Parameter 'key')) (Value cannot be null. (Parameter 'key')) (Value cannot be null. (Parameter 'key'))
  ----> System.ArgumentNullException : Value cannot be null. (Parameter 'key')
  ----> System.ArgumentNullException : Value cannot be null. (Parameter 'key')
  ----> System.ArgumentNullException : Value cannot be null. (Parameter 'key')
  ----> System.ArgumentNullException : Value cannot be null. (Parameter 'key')
   at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
   at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
   at System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException)
   at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
   at System.Threading.Tasks.Parallel.For(Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body)
   at XXXXX.Tests.Tests.Smoke.GroupDelete.GroupDeleteEntities.CreateAndDeleteManyItems() in ..\XXXXX.SeleniumTests\Tests\Tests\Smoke\GroupDelete\GroupDeleteEntities.cs:line 34
--ArgumentNullException
   at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNullException()
   at System.Collections.Concurrent.ConcurrentDictionary`2.TryGetValue(TKey key, TValue& value)
   at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)
   at Allure.Commons.Storage.AllureStorage.Get[T](String uuid)
   at Allure.Commons.Storage.AllureStorage.AddStep(String parentUuid, String uuid, StepResult stepResult)
   at Allure.Commons.AllureLifecycle.StartStep(String parentUuid, String uuid, StepResult stepResult)
   at Allure.Commons.AllureLifecycle.StartStep(String uuid, StepResult result)
   at Allure.Commons.AllureLifecycle.StepRunner[TResult](String stepName, Delegate del, Boolean throwEx, Status stepStatusIfFailed, Object[] stepParams)
   at Allure.Commons.AllureLifecycle.RunStep(String stepName, Action stepBody, Object[] stepParams)
   at XXXXX.Tests.Tests.Smoke.GroupDelete.GroupDeleteEntities.<>c.<CreateAndDeleteManyItems>b__1_0(Int32 i) in ..\XXXXX.SeleniumTests\Tests\Tests\Smoke\GroupDelete\GroupDeleteEntities.cs:line 36
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
--ArgumentNullException
   at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNullException()
   at System.Collections.Concurrent.ConcurrentDictionary`2.TryGetValue(TKey key, TValue& value)
   at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)
   at Allure.Commons.Storage.AllureStorage.Get[T](String uuid)
   at Allure.Commons.Storage.AllureStorage.AddStep(String parentUuid, String uuid, StepResult stepResult)
   at Allure.Commons.AllureLifecycle.StartStep(String parentUuid, String uuid, StepResult stepResult)
   at Allure.Commons.AllureLifecycle.StartStep(String uuid, StepResult result)
   at Allure.Commons.AllureLifecycle.StepRunner[TResult](String stepName, Delegate del, Boolean throwEx, Status stepStatusIfFailed, Object[] stepParams)
   at Allure.Commons.AllureLifecycle.RunStep(String stepName, Action stepBody, Object[] stepParams)
   at XXXXX.Tests.Tests.Smoke.GroupDelete.GroupDeleteEntities.<>c.<CreateAndDeleteManyItems>b__1_0(Int32 i) in ..\XXXXX.SeleniumTests\Tests\Tests\Smoke\GroupDelete\GroupDeleteEntities.cs:line 36
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
--ArgumentNullException
   at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNullException()
   at System.Collections.Concurrent.ConcurrentDictionary`2.TryGetValue(TKey key, TValue& value)
   at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)
   at Allure.Commons.Storage.AllureStorage.Get[T](String uuid)
   at Allure.Commons.Storage.AllureStorage.AddStep(String parentUuid, String uuid, StepResult stepResult)
   at Allure.Commons.AllureLifecycle.StartStep(String parentUuid, String uuid, StepResult stepResult)
   at Allure.Commons.AllureLifecycle.StartStep(String uuid, StepResult result)
   at Allure.Commons.AllureLifecycle.StepRunner[TResult](String stepName, Delegate del, Boolean throwEx, Status stepStatusIfFailed, Object[] stepParams)
   at Allure.Commons.AllureLifecycle.RunStep(String stepName, Action stepBody, Object[] stepParams)
   at XXXXX.Tests.Tests.Smoke.GroupDelete.GroupDeleteEntities.<>c.<CreateAndDeleteManyItems>b__1_0(Int32 i) in ..\XXXXX.SeleniumTests\Tests\Tests\Smoke\GroupDelete\GroupDeleteEntities.cs:line 36
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
--ArgumentNullException
   at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNullException()
   at System.Collections.Concurrent.ConcurrentDictionary`2.TryGetValue(TKey key, TValue& value)
   at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)
   at Allure.Commons.Storage.AllureStorage.Get[T](String uuid)
   at Allure.Commons.Storage.AllureStorage.AddStep(String parentUuid, String uuid, StepResult stepResult)
   at Allure.Commons.AllureLifecycle.StartStep(String parentUuid, String uuid, StepResult stepResult)
   at Allure.Commons.AllureLifecycle.StartStep(String uuid, StepResult result)
   at Allure.Commons.AllureLifecycle.StepRunner[TResult](String stepName, Delegate del, Boolean throwEx, Status stepStatusIfFailed, Object[] stepParams)
   at Allure.Commons.AllureLifecycle.RunStep(String stepName, Action stepBody, Object[] stepParams)
   at XXXXX.Tests.Tests.Smoke.GroupDelete.GroupDeleteEntities.<>c.<CreateAndDeleteManyItems>b__1_0(Int32 i) in ..\XXXXX.SeleniumTests\Tests\Tests\Smoke\GroupDelete\GroupDeleteEntities.cs:line 36
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()

Expected The separated unsorted steps in the Allure report on the one level have been expected.

Question Am I do something wrong? If so, may you offer the workaround? Or Is It bug?

Versions

Noksa commented 4 years ago

Hello. This is the bug.