Skip to content

Commit

Permalink
test: add reproducer test
Browse files Browse the repository at this point in the history
Add test which shows that not all jobs are handled but activated
  • Loading branch information
ChrisKujawa committed Aug 20, 2021
1 parent 6051efc commit 257c4ac
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions Client.IntegrationTests/JobWorkerMultiPartitionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using Zeebe.Client;
using Zeebe.Client.Api.Responses;

namespace Client.IntegrationTests
{
[TestFixture]
public class JobWorkerMultiPartitionTest
{
private static readonly string DemoProcessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "oneTaskProcess.bpmn");

private readonly ZeebeIntegrationTestHelper testHelper = ZeebeIntegrationTestHelper.Latest().withPartitionCount(3);
private IZeebeClient zeebeClient;
private long processDefinitionKey;

[OneTimeSetUp]
public async Task Setup()
{
zeebeClient = await testHelper.SetupIntegrationTest();
var deployResponse = await zeebeClient.NewDeployCommand()
.AddResourceFile(DemoProcessPath)
.Send();
processDefinitionKey = deployResponse.Processes[0].ProcessDefinitionKey;
}

[OneTimeTearDown]
public async Task Stop()
{
await testHelper.TearDownIntegrationTest();
}

[Test]
public async Task ShouldCompleteProcess()
{
// given
var handledJobs = new List<IJob>();
foreach (int i in Enumerable.Range(1, 3))
{
await zeebeClient.NewCreateProcessInstanceCommand()
.ProcessDefinitionKey(processDefinitionKey)
.Send();
}

// when
using (var signal = new EventWaitHandle(false, EventResetMode.AutoReset))
{
using (zeebeClient.NewWorker()
.JobType("oneTask")
.Handler(async (jobClient, job) =>
{
await jobClient.NewCompleteJobCommand(job).Send();
handledJobs.Add(job);
if (handledJobs.Count >= 3)
{
signal.Set();
}
})
.MaxJobsActive(5)
.Name("csharpWorker")
.Timeout(TimeSpan.FromHours(10))
.PollInterval(TimeSpan.FromSeconds(5))
.Open())
{
signal.WaitOne(TimeSpan.FromSeconds(5));

}
}

Assert.AreEqual(3, handledJobs.Count);
}
}
}

0 comments on commit 257c4ac

Please sign in to comment.