60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using franz;
|
|
using NUnit.Framework;
|
|
|
|
namespace franz.tests
|
|
{
|
|
[TestFixture]
|
|
public class Tests
|
|
{
|
|
Telefranz f1;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
f1 = new Telefranz("libfranztest1", "focalor:9092");
|
|
}
|
|
|
|
[Test]
|
|
public async Task reportsToSoundoff()
|
|
{
|
|
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;
|
|
// }
|
|
}
|
|
});
|
|
await Task.Delay(2000);
|
|
f1.ProduceMessage(new silver_messages.global.sound_off());
|
|
Task.WaitAny(
|
|
Task.Run(async () => {
|
|
while(f1Reported == false)
|
|
{
|
|
TestContext.Out.WriteLine("not ready, giving another 100ms");
|
|
await Task.Delay(100);
|
|
}
|
|
TestContext.Out.WriteLine("done, ready, green");
|
|
}),
|
|
Task.Run(async () => {
|
|
await Task.Delay(30000);
|
|
TestContext.Out.WriteLine("time up");
|
|
Assert.Fail();
|
|
})
|
|
);
|
|
}
|
|
}
|
|
} |