Skip to content

Commit 9cf5181

Browse files
authored
Merge pull request danielgerlag#212 from dr-BEat/feat/MemoryPersistanceEnvironments
Added environments to MemoryPersistanceProvider for parallel testing
2 parents 7a9c35c + 4bfba49 commit 9cf5181

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/WorkflowCore/Services/DefaultProviders/MemoryPersistenceProvider.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Threading.Tasks;
@@ -14,11 +15,26 @@ namespace WorkflowCore.Services
1415
/// </summary>
1516
public class MemoryPersistenceProvider : IPersistenceProvider
1617
{
18+
private static readonly ConcurrentDictionary<string, Tuple<List<WorkflowInstance>, List<EventSubscription>, List<Event>, List<ExecutionError>>> Environments =
19+
new ConcurrentDictionary<string, Tuple<List<WorkflowInstance>, List<EventSubscription>, List<Event>, List<ExecutionError>>>();
20+
private readonly List<WorkflowInstance> _instances;
21+
private readonly List<EventSubscription> _subscriptions;
22+
private readonly List<Event> _events;
23+
private readonly List<ExecutionError> _errors;
24+
25+
public MemoryPersistenceProvider()
26+
: this("")
27+
{
28+
}
1729

18-
private static List<WorkflowInstance> _instances = new List<WorkflowInstance>();
19-
private static List<EventSubscription> _subscriptions = new List<EventSubscription>();
20-
private static List<Event> _events = new List<Event>();
21-
private static List<ExecutionError> _errors = new List<ExecutionError>();
30+
public MemoryPersistenceProvider(string environmentKey)
31+
{
32+
var environment = Environments.GetOrAdd(environmentKey, _ => Tuple.Create(new List<WorkflowInstance>(), new List<EventSubscription>(), new List<Event>(), new List<ExecutionError>()));
33+
_instances = environment.Item1;
34+
_subscriptions = environment.Item2;
35+
_events = environment.Item3;
36+
_errors = environment.Item4;
37+
}
2238

2339
public async Task<string> CreateNewWorkflow(WorkflowInstance workflow)
2440
{

0 commit comments

Comments
 (0)