TimoHeiten / zer0mqXt

type safe zeroMQ patterns with dotnet core and C#
MIT License
0 stars 0 forks source link

[62] added fluentassertions analyzers #69

Open Flash0ver opened 2 years ago

Flash0ver commented 2 years ago

Closes #62

Flash0ver commented 2 years ago

heitech.zer0mqXt.core.tests.ClientServerInProcTests.RetryWorksForTheSpecifiedRetryCount(retryCount: 1, expectedSuccess: True) fails on CI with a System.NullReferenceException but passes locally at ClientServerInProcTests.cs:line 166 var result = await client?.RequestAsync<Request, Response>(new Request { RequestNumber = 21 });

I believe we ran into a C# pitfall: null-conditional operators + await: await cannot deal with awaitables which are null.

Here's a simplified version of the lowered code:

// ...
awaiter = ((client != null) ? client.MyAsync() : null).GetAwaiter();
if (!awaiter.IsCompleted)
{
    // ...

If we enable nullable reference types, we do get a diagnostic: Warning CS8602 Dereference of a possibly null reference.

But I'm unsure if just if not null-guarding that IClient.RequestAsync invocation would actually fix it, or just hide the actual problem. What do you think?