franz/franz.tests/UnitTest1.cs

60 lines
1.9 KiB
C#
Raw Normal View History

2021-06-19 01:07:12 -04:00
using System;
using System.Threading.Tasks;
using franz;
using NUnit.Framework;
namespace franz.tests
{
[TestFixture]
public class Tests
{
Telefranz f1;
[SetUp]
public void Setup()
{
2021-06-29 04:20:09 -04:00
f1 = new Telefranz("libfranztest1", "focalor:9092");
2021-06-19 01:07:12 -04:00
}
[Test]
public async Task reportsToSoundoff()
2021-06-19 01:07:12 -04:00
{
var f1Reported = false;
f1.addHandler((silver_messages.global.report r) => {
switch(r.name)
{
case "libfranztest1":
{
f1Reported = true;
TestContext.Out.WriteLine("f1 reported");
break;
}
//lol you can't have more than one kafka interface, right? so you can't do any (useful) tests on the sending of messages :P
// case "libfranztest2":
// {
// f2Reported = true;
// TestContext.Out.WriteLine("f2 reported");
// break;
// }
2021-06-19 01:07:12 -04:00
}
});
await Task.Delay(2000);
2021-06-19 01:07:12 -04:00
f1.ProduceMessage(new silver_messages.global.sound_off());
Task.WaitAny(
Task.Run(async () => {
while(f1Reported == false)
2021-06-19 01:07:12 -04:00
{
TestContext.Out.WriteLine("not ready, giving another 100ms");
2021-06-19 01:07:12 -04:00
await Task.Delay(100);
}
TestContext.Out.WriteLine("done, ready, green");
2021-06-19 01:07:12 -04:00
}),
Task.Run(async () => {
await Task.Delay(30000);
2021-06-19 01:07:12 -04:00
TestContext.Out.WriteLine("time up");
Assert.Fail();
})
);
}
}
}