Skip to content
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

Remove blocking in IMessageProcessingStrategy #440

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using JustSaying.Messaging.MessageProcessingStrategies;
using JustSaying.TestingFramework;

namespace JustSaying.UnitTests.AwsTools.MessageHandling.SqsNotificationListener.Support
{
public class ThrowingBeforeMessageProcessingStrategy : IMessageProcessingStrategy
{
public int MaxWorkers => int.MaxValue;

public int AvailableWorkers
{
get
{
if (_firstTime)
{
return 0;
}

return int.MaxValue;
}
}

private readonly TaskCompletionSource<object> _doneSignal;
private bool _firstTime = true;

public ThrowingBeforeMessageProcessingStrategy(TaskCompletionSource<object> doneSignal)
{
_doneSignal = doneSignal;
}

public Task WaitForAvailableWorkers()
{
if (_firstTime)
{
_firstTime = false;
Fail();
}
return Task.FromResult(true);
}

public void StartWorker(Func<Task> action, CancellationToken cancellationToken)
{
}

private void Fail()
{
Tasks.DelaySendDone(_doneSignal);
throw new TestException("Thrown by test ProcessMessage");
}

}
}
using System;
using System.Threading;
using System.Threading.Tasks;
using JustSaying.Messaging.MessageProcessingStrategies;
using JustSaying.TestingFramework;

namespace JustSaying.UnitTests.AwsTools.MessageHandling.SqsNotificationListener.Support
{
public class ThrowingBeforeMessageProcessingStrategy : IMessageProcessingStrategy
{
public int MaxWorkers => int.MaxValue;

public int AvailableWorkers
{
get
{
if (_firstTime)
{
return 0;
}

return int.MaxValue;
}
}

private readonly TaskCompletionSource<object> _doneSignal;
private bool _firstTime = true;

public ThrowingBeforeMessageProcessingStrategy(TaskCompletionSource<object> doneSignal)
{
_doneSignal = doneSignal;
}

public Task WaitForAvailableWorkers()
{
if (_firstTime)
{
_firstTime = false;
Fail();
}
return Task.FromResult(true);
}

public Task StartWorker(Func<Task> action, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

private void Fail()
{
Tasks.DelaySendDone(_doneSignal);
throw new TestException("Thrown by test ProcessMessage");
}

}
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using JustSaying.Messaging.MessageProcessingStrategies;
using JustSaying.TestingFramework;

namespace JustSaying.UnitTests.AwsTools.MessageHandling.SqsNotificationListener.Support
{
public class ThrowingDuringMessageProcessingStrategy : IMessageProcessingStrategy
{
public int MaxWorkers => int.MaxValue;

public int AvailableWorkers => int.MaxValue;

private readonly TaskCompletionSource<object> _doneSignal;
private bool _firstTime = true;

public ThrowingDuringMessageProcessingStrategy(TaskCompletionSource<object> doneSignal)
{
_doneSignal = doneSignal;
}

public async Task WaitForAvailableWorkers()
{
await Task.Yield();
}

public void StartWorker(Func<Task> action, CancellationToken cancellationToken)
{
if (_firstTime)
{
_firstTime = false;
Fail();
}
}

private void Fail()
{
Tasks.DelaySendDone(_doneSignal);
throw new TestException("Thrown by test ProcessMessage");
}

}
}
using System;
using System.Threading;
using System.Threading.Tasks;
using JustSaying.Messaging.MessageProcessingStrategies;
using JustSaying.TestingFramework;

namespace JustSaying.UnitTests.AwsTools.MessageHandling.SqsNotificationListener.Support
{
public class ThrowingDuringMessageProcessingStrategy : IMessageProcessingStrategy
{
public int MaxWorkers => int.MaxValue;

public int AvailableWorkers => int.MaxValue;

private readonly TaskCompletionSource<object> _doneSignal;
private bool _firstTime = true;

public ThrowingDuringMessageProcessingStrategy(TaskCompletionSource<object> doneSignal)
{
_doneSignal = doneSignal;
}

public async Task WaitForAvailableWorkers()
{
await Task.Yield();
}

public Task StartWorker(Func<Task> action, CancellationToken cancellationToken)
{
if (_firstTime)
{
_firstTime = false;
return Fail();
}

return Task.CompletedTask;
}

private Task Fail()
{
Tasks.DelaySendDone(_doneSignal);
throw new TestException("Thrown by test ProcessMessage");
}

}
}
Loading