Test how the logger behaves in async mode#83
Conversation
|
@tagomoris This is a follow-up of #82, I prefer to send these test changes separately to ease the review. New test cases are marked as broken for now, but #82 is going to fix them 😉 |
8361918 to
e196026
Compare
|
Is there anything I could do to ease the review of this PR? 🙂 |
|
Ah, sorry for that I've not thought you'd finished the work on this (because a commit followed your comment). |
tagomoris
left a comment
There was a problem hiding this comment.
I've read through the entire diff and it looks good for now.
But let me check this once again later (tomorrow or next week?). It's complex and requires so much care.
| case <-time.After(duration): | ||
| t.Fatalf("time out after %s: %s", duration.String(), reason) | ||
| case <-done: | ||
| return |
There was a problem hiding this comment.
Should we check case <-done before case <-time.After()?
(I'm not sure if the order of code affects the order of processes actually called)
There was a problem hiding this comment.
By looking at Go spec (see here), I'd say the order doesn't matter since there're no default case and both receive cases here are blocking 😉
| &TestMessage{Foo: "bar"}, | ||
| "[\"tag_name\",1482493046,{\"foo\":\"bar\"},{}]", | ||
| func TestCloseOnFailingAsyncReconnect(t *testing.T) { | ||
| t.Skip("Broken tests") |
There was a problem hiding this comment.
To be clear - With #82, we can remove this line, right?
There was a problem hiding this comment.
I pushed a newer version of #82 with the commit from this PR and a reworked version of my initial fix. As you can see here, both t.Skip() are removed 🙂
I'll rebase #82 once this current PR got merged 😉
EDIT: btw, just saw the CI is failing on #82 but that's due to a bad rebase (he incriminated line shall have been removed). I'll fix that once this PR is merged to not rebase too many times as this is actually spamming the original issue on moby/moby repo.
| if config.Timeout == 0 { | ||
| config.Timeout = defaultTimeout | ||
| } |
There was a problem hiding this comment.
Why not having all if config.ParameteName ... clauses about default values here, instead of newWithDialer?
Those configuration defaults are of Logger, and there seems no strong reason to do it in newWithDialer.
Having all the similar things in the same place should be valuable for readability.
There was a problem hiding this comment.
Ah, code in test cases are assuming that defaults are set in newWithDialer. Hmm.
There was a problem hiding this comment.
Indeed, I moved most of parameters initializations to newWithDialer() because I didn't want to refactor test cases too much. However, the timeout is needed only when the dialer is created by New().
tagomoris
left a comment
There was a problem hiding this comment.
This change looks good to me, but I have a concern about the difficulty newly introduced into testDialer and Conn. Now I understood those behaviors, but I can't be sure that I'll be able to work on those codes immediately when something is reported about it in the future.
That should be true for other people who will try to add new test cases.
The concern above could be unhelpful because this change wants to manage difficult things.
Improving naming (of writesCh, nextWriteCh ...) could be helpful, but I have no good idea about good names of them :(
So, I want to request to have short docs about how to use those test stubs, with sample code.
I'm ok either long comments in the test code file or an independent .md file.
It's best to have some sections about how to simulate
- successful connection establishment, successful data transferring
- successful connection establishment, failing data transferring
- failing connection establishment
- (and other possible scenarios)
@NiR- How do you feel about this idea?
8fb0baa to
0465216
Compare
|
@tagomoris Sorry for the long delay. I added ~120 lines of comments to better explain how things work, that include some examples, and explanations about the differences between test cases for sync and async modes. About the namings, after revisiting this PR I wonder if following changes would make sense:
These are small changes but maybe this would made things easier to understand. WDYT? |
|
@akerouanton The added comments look really nice. Thanks! The proposed renames look also nice. 👍 |
0465216 to
c19c097
Compare
New testcases have been written to test if PostWithTime() and Close() are working as expected. More specifically, they test if Close() succeed with all combination of options (Async + ForceStopAsyncSend). Tests on PostWithTime() are divided into two parts: * With transient network failure ; * And without any ; And tests on Close() are divided into two parts: * CloseOnAsyncConnect: When no logs have been written yet ; * CloseOnAsyncReconnect: When there're pending logs to write ; Finally, the test `Test_send_WritePendingToConn` has been removed because it was relying too much on the logger internals to test the logger's behavior from an API user PoV. And the init() that was starting a tcp listener has been removed to make the tests easier to execute (otherwise, we've to wait for go test to timeout before re-running it). Signed-off-by: Albin Kerouanton <albin.kerouanton@knplabs.com>
I just pushed these changes 😉 |
|
Merged. @akerouanton Thank you! |
|
bump @tagomoris @akerouanton |
New testcases have been written to test if PostWithTime() and Close()
are working as expected. More specifically, they test if Close() succeed
with all combination of options (Async + ForceStopAsyncSend).
Tests on PostWithTime() are divided into two parts:
And tests on Close() are divided into two parts:
Finally, the test
Test_send_WritePendingToConnhas been removedbecause it was relying too much on the logger internals to test the
logger's behavior from an API user PoV. And the init() that was starting
a tcp listener has been removed to make the tests easier to execute
(otherwise, we've to wait for go test to timeout before re-running it).