just now it passed. I have changed nothing. it took 4 seconds.

This commit is contained in:
Adam R. Grey 2021-06-19 05:39:39 -04:00
parent c3fdf8fb9b
commit 634713171d
3 changed files with 14 additions and 25 deletions

View File

@ -19,7 +19,7 @@ namespace franz.tests
} }
[Test] [Test]
public void reportsToSoundoff() public async Task reportsToSoundoff()
{ {
var f1Reported = false; var f1Reported = false;
var f2Reported = false; var f2Reported = false;
@ -42,6 +42,7 @@ namespace franz.tests
}); });
f1.StartListening(); f1.StartListening();
f2.StartListening(); f2.StartListening();
await Task.Delay(2000);
f1.ProduceMessage(new silver_messages.global.sound_off()); f1.ProduceMessage(new silver_messages.global.sound_off());
Task.WaitAny( Task.WaitAny(
Task.Run(async () => { Task.Run(async () => {
@ -53,7 +54,7 @@ namespace franz.tests
//TestContext.Out.WriteLine("done, ready, green"); //TestContext.Out.WriteLine("done, ready, green");
}), }),
Task.Run(async () => { Task.Run(async () => {
await Task.Delay(10000); await Task.Delay(120000);
TestContext.Out.WriteLine("time up"); TestContext.Out.WriteLine("time up");
Assert.Fail(); Assert.Fail();
}) })

View File

@ -123,36 +123,24 @@ namespace franz
StopListening(); StopListening();
listenTask = Task.Run(() => listenTask = Task.Run(() =>
{ {
try shouldListen = true;
while (shouldListen)
{ {
shouldListen = true; var cr = consumer.Consume();
while (shouldListen) if (cr != null)
{ {
var cr = consumer.Consume(125); var typeHaver = JsonConvert.DeserializeAnonymousType(cr.Message.Value, new { type = "" });
if (cr != null) var messageType = handlers.Keys.FirstOrDefault(hkey => hkey.ToString() == typeHaver.type && handlers[hkey].Count > 0);
if (messageType != null)
{ {
var typeHaver = JsonConvert.DeserializeAnonymousType(cr.Message.Value, new { type = "" }); var message = JsonConvert.DeserializeObject(cr.Message.Value, messageType);
var messageType = handlers.Keys.FirstOrDefault(hkey => hkey.ToString() == typeHaver.type && handlers[hkey].Count > 0); foreach (var handling in handlers[messageType])
if (messageType != null)
{ {
var message = JsonConvert.DeserializeObject(cr.Message.Value, messageType); handling(message as silver_messages.message);
foreach (var handling in handlers[messageType])
{
handling(message as silver_messages.message);
}
} }
} }
} }
} }
catch (System.OperationCanceledException)
{
Console.WriteLine("cancelled");
}
catch (Confluent.Kafka.ConsumeException e)
{
Console.Error.WriteLine(JsonConvert.SerializeObject(e));
throw;
}
}); });
} }
public void StopListening() public void StopListening()

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
<PackageId>franz</PackageId> <PackageId>silvermeddlists.franz</PackageId>
<Version>0.0.1</Version> <Version>0.0.1</Version>
<Authors>adam</Authors> <Authors>adam</Authors>
<Company>Silver Meddlists</Company> <Company>Silver Meddlists</Company>