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

View File

@ -123,36 +123,24 @@ namespace franz
StopListening();
listenTask = Task.Run(() =>
{
try
shouldListen = true;
while (shouldListen)
{
shouldListen = true;
while (shouldListen)
var cr = consumer.Consume();
if (cr != null)
{
var cr = consumer.Consume(125);
if (cr != null)
var typeHaver = JsonConvert.DeserializeAnonymousType(cr.Message.Value, new { type = "" });
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 messageType = handlers.Keys.FirstOrDefault(hkey => hkey.ToString() == typeHaver.type && handlers[hkey].Count > 0);
if (messageType != null)
var message = JsonConvert.DeserializeObject(cr.Message.Value, messageType);
foreach (var handling in handlers[messageType])
{
var message = JsonConvert.DeserializeObject(cr.Message.Value, messageType);
foreach (var handling in handlers[messageType])
{
handling(message as silver_messages.message);
}
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()

View File

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