Skip to content

Fix race condition on stop #1081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/WorkflowCore.Testing/WorkflowTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class WorkflowTest<TWorkflow, TData> : IDisposable
protected IWorkflowHost Host;
protected IPersistenceProvider PersistenceProvider;
protected List<StepError> UnhandledStepErrors = new List<StepError>();
private bool isDisposed;

protected virtual void Setup()
{
Expand Down Expand Up @@ -116,9 +117,22 @@ protected TData GetData(string workflowId)
return (TData)instance.Data;
}

protected virtual void Dispose(bool disposing)
{
if (!isDisposed)
{
if (disposing)
{
Host.Stop();
}
isDisposed = true;
}
}

public void Dispose()
{
Host.Stop();
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected override async Task ProcessItem(string itemId, CancellationToken cance
finally
{
WorkflowActivity.Enrich(result);
await _persistenceStore.PersistWorkflow(workflow, result?.Subscriptions, cancellationToken);
await _persistenceStore.PersistWorkflow(workflow, result?.Subscriptions);
await QueueProvider.QueueWork(itemId, QueueType.Index);
_greylist.Remove($"wf:{itemId}");
}
Expand Down
2 changes: 1 addition & 1 deletion test/Docker.Testify/Docker.Testify.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="Docker.DotNet" Version="3.125.2" />
<PackageReference Include="Docker.DotNet" Version="3.125.10" />
<PackageReference Include="System.Diagnostics.Process" Version="4.3.0" />
<PackageReference Include="System.Net.NetworkInformation" Version="4.3.0" />
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
Expand Down
47 changes: 47 additions & 0 deletions test/WorkflowCore.IntegrationTests/Scenarios/StopScenario.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using WorkflowCore.Models.LifeCycleEvents;
using WorkflowCore.Testing;
using Xunit;

namespace WorkflowCore.IntegrationTests.Scenarios
{
public class StopScenario : WorkflowTest<StopScenario.StopWorkflow, object>
{
public class StopWorkflow : IWorkflow
{
public string Id => "StopWorkflow";
public int Version => 1;
public void Build(IWorkflowBuilder<object> builder)
{
builder.StartWith(context => ExecutionResult.Next());
}
}

public StopScenario() => Setup();

[Fact]
public async Task Scenario()
{
var tcs = new TaskCompletionSource<object>();
Host.OnLifeCycleEvent += async (evt) =>
{
if (evt is WorkflowCompleted)
{
await Host.StopAsync(CancellationToken.None);
tcs.SetResult(default);
}
};

var workflowId = StartWorkflow(default);
await tcs.Task;

GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
}

protected override void Dispose(bool disposing) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using Amazon.DynamoDBv2;
using Microsoft.Extensions.DependencyInjection;
using WorkflowCore.IntegrationTests.Scenarios;
using Xunit;

namespace WorkflowCore.Tests.DynamoDB.Scenarios
{
[Collection("DynamoDb collection")]
public class DynamoStopScenario : StopScenario
{
protected override void ConfigureServices(IServiceCollection services)
{
var cfg = new AmazonDynamoDBConfig {ServiceURL = DynamoDbDockerSetup.ConnectionString};
services.AddWorkflow(x => x.UseAwsDynamoPersistence(DynamoDbDockerSetup.Credentials, cfg, "tests-"));
}
}
}
16 changes: 16 additions & 0 deletions test/WorkflowCore.Tests.MongoDB/Scenarios/MongoStopScenario.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using WorkflowCore.IntegrationTests.Scenarios;
using Xunit;

namespace WorkflowCore.Tests.MongoDB.Scenarios
{
[Collection("Mongo collection")]
public class MongoStopScenario : StopScenario
{
protected override void ConfigureServices(IServiceCollection services)
{
services.AddWorkflow(x => x.UseMongoDB(MongoDockerSetup.ConnectionString, "integration-tests"));
}
}
}
16 changes: 16 additions & 0 deletions test/WorkflowCore.Tests.MySQL/Scenarios/MysqlStopScenario.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using WorkflowCore.IntegrationTests.Scenarios;
using Xunit;

namespace WorkflowCore.Tests.MySQL.Scenarios
{
[Collection("Mysql collection")]
public class MysqlStopScenario : StopScenario
{
protected override void ConfigureServices(IServiceCollection services)
{
services.AddWorkflow(x => x.UseMySQL(MysqlDockerSetup.ScenarioConnectionString, true, true));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using WorkflowCore.IntegrationTests.Scenarios;
using Xunit;

namespace WorkflowCore.Tests.PostgreSQL.Scenarios
{
[Collection("Postgres collection")]
public class PostgresStopScenario : StopScenario
{
protected override void ConfigureServices(IServiceCollection services)
{
services.AddWorkflow(x => x.UsePostgreSQL(PostgresDockerSetup.ScenarioConnectionString, true, true));
}
}
}
16 changes: 16 additions & 0 deletions test/WorkflowCore.Tests.Redis/Scenarios/RedisStopScenario.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using WorkflowCore.IntegrationTests.Scenarios;
using Xunit;

namespace WorkflowCore.Tests.Redis.Scenarios
{
[Collection("Redis collection")]
public class RedisStopScenario : StopScenario
{
protected override void ConfigureServices(IServiceCollection services)
{
services.AddWorkflow(x => x.UseRedisPersistence(RedisDockerSetup.ConnectionString, "scenario-"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using WorkflowCore.IntegrationTests.Scenarios;
using Xunit;

namespace WorkflowCore.Tests.SqlServer.Scenarios
{
[Collection("SqlServer collection")]
public class SqlServerStopScenario : StopScenario
{
protected override void ConfigureServices(IServiceCollection services)
{
services.AddWorkflow(x => x.UseSqlServer(SqlDockerSetup.ScenarioConnectionString, true, true));
}
}
}
17 changes: 17 additions & 0 deletions test/WorkflowCore.Tests.Sqlite/Scenarios/SqliteStopScenario.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using WorkflowCore.IntegrationTests.Scenarios;
using WorkflowCore.Tests.Sqlite;
using Xunit;

namespace WorkflowCore.Tests.Sqlite.Scenarios
{
[Collection("Sqlite collection")]
public class SqliteStopScenario : StopScenario
{
protected override void ConfigureServices(IServiceCollection services)
{
services.AddWorkflow(x => x.UseSqlite(SqliteSetup.ConnectionString, true));
}
}
}
2 changes: 1 addition & 1 deletion test/WorkflowCore.Tests.Sqlite/SqliteCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class SqliteCollection : ICollectionFixture<SqliteSetup>

public class SqliteSetup : IDisposable
{
public string ConnectionString { get; set; }
public static string ConnectionString { get; set; }
Copy link
Owner

Choose a reason for hiding this comment

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

Why does this need to be made static?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to have simple access to the value from the new SqliteStopScenario as well as aligning it with the way all the other scenario setups have static connection strings.


public SqliteSetup()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ namespace WorkflowCore.Tests.Sqlite
[Collection("Sqlite collection")]
public class SqlitePersistenceProviderFixture : BasePersistenceFixture
{
string _connectionString;

public SqlitePersistenceProviderFixture(SqliteSetup setup)
{
_connectionString = setup.ConnectionString;
}

protected override IPersistenceProvider Subject
{
get
{
var db = new EntityFrameworkPersistenceProvider(new SqliteContextFactory(_connectionString), true, false);
{
var db = new EntityFrameworkPersistenceProvider(new SqliteContextFactory(SqliteSetup.ConnectionString), true, false);
db.EnsureStoreExists();
return db;
}
Expand Down