NCIOCPL / glossary-api

API for Dictionary of Cancer Terms, Dictionary of Genetics Terms, and other Glossary documents.
0 stars 5 forks source link

Fix GetSuggestions_TestInvalidResponse unit test failure #157

Closed blairlearn closed 2 years ago

blairlearn commented 2 years ago

Issue description

Following the update to Elasticsearch 7.9 and the NEST client, the GetSuggestions_TestInvalidResponse test now fails.

The test fails when run from the command line via dotnet test but succeeds when run in the debugger.

ESTIMATE TBD

Steps to reproduce the issue

  1. Run the unit tests

What's the expected result?

What's the actual result?

Additional details / screenshot

Related Tickets

blairlearn commented 2 years ago

This appears to have been caused by the Stream object containing the mock response not being Disposed properly.

This has also surfaced NCIOCPL/NCI.OCPL.Api.Shared#41

blairlearn commented 2 years ago

There seems to be something subtly "wrong" about the manner in which we place a stream into the response object when testing handling of partial (i.e. "interrupted") responses. This impacts both GetSuggestions_TestInvalidResponse and GetCount_InvalidResponse.

Annoyingly, this only happens when the tests are run as a whole, not when being debugged.

Clearly, it's a race condition.

Putting a using around the stream assignment allows the test to run, however since this closes the stream, it may simply be causing NEST to encounter, and swallow, an exception due to an attempt at reading a closed stream.

Similarly, adding code to the query service to write a dump of the response object also causes the error to go away.

In the end, with agreement from @bryanpizzillo, since all we really care about on those tests is setting the response, the fix is to replace the ElasticsearchInterceptingConnection with NEST's InMemoryConnection.