Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Conversation

@analogrelay
Copy link
Contributor

No changes to product code at all, just to test code.

  • There was a lot of duplication in these tests, so I introduced a few helpers (mostly just the ones I had already done with the AbortAsync tests in Making HttpConnection restartable (C#) #1147)
  • The try { ... } finally { DisposeAsync() } pattern gets noisy fast so I added WithConnectionAsync() which runs a provided delegate in the body of that try-finally pattern
  • Lots of Moq usage that just ends up doing the same thing. So I introduced TestTransport and TestHttpMessageHandler code to remove most of the duplication.
  • Lots of TCSes everywhere. Many of them are doing the job that the SyncPoint helper I introduced in Making HttpConnection restartable (C#) #1147 does (having a pair of TCSes to allow test code to wait for code-under-test to reach a certain point and then release it to continue after a condition is met). So I refactored to use that.
  • One big giant test file was getting unwieldy so I split it into other files and used nested classes to group tests to allow you to easily run each group separately.
  • A couple tests were a bit weird and got refactored/renamed:
    • EventsAreNotRunningOnMainLoop was depending upon a race. It was testing that when TryWrite on the channel was called, a TryRead immediately following would fail because the HttpConnection receive loop already read the message. This depends on the way inline-continuations work in Channels and may break with other configurations. The refactored test waits for WaitToReadAsync to block, which should be more reliable
    • EventQueueTimeoutWithException just seemed to be checking that exceptions in OnReceive are handled, which other tests already do. So I just removed it.

* Add some helpers to reduce duplication
* Refactor some tests to clarify what they test
* Removed a few redundant test cases
@davidfowl
Copy link
Member

wtf is a SyncPoint...

@analogrelay
Copy link
Contributor Author

Read the code and find out. It's a pair of TCSes that replace a bunch of repeated code in our tests. WaitToContinue triggers the TCS attached to WaitForSyncPoint and Continue triggers the TCS attached to WaitToContinue. We were implementing this with pairs of TCSes in each test and it was super noisy.

@@ -0,0 +1,128 @@
using System;
Copy link

@muratg muratg Dec 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: (c) notice. </ TroyMode>

@@ -0,0 +1,91 @@
using System;
Copy link

@muratg muratg Dec 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(c) here and other new files.

Copy link

@muratg muratg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! There could be further clean-up but no need to block this one.

@@ -0,0 +1,366 @@
using System;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy

@@ -0,0 +1,104 @@
using System;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy

@@ -0,0 +1,119 @@
using System;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy

{
return Task.FromException<HttpResponseMessage>(new InvalidOperationException($"Http endpoint not implemented: {request.RequestUri}"));
}
// Just block until cancelled
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canceled

@analogrelay
Copy link
Contributor Author

I'm going to take a look at some of the test flakiness after this. I don't like how hard it is to get the checks to go green.

@analogrelay analogrelay merged commit 3bb7125 into dev Dec 19, 2017
@analogrelay analogrelay deleted the anurse/http-connection-test-clean-up branch December 19, 2017 19:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants