Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix test failing because of timeout that aren't testing timing #375

Merged
merged 7 commits into from
Dec 14, 2020
Merged

fix test failing because of timeout that aren't testing timing #375

merged 7 commits into from
Dec 14, 2020

Conversation

scottf
Copy link
Contributor

@scottf scottf commented Dec 13, 2020

These test are flappers, failing because of timeout. But they are not testing timing, they are testing state, so timeout should not matter.

While I was in these files... nit fixed to use assertSame when testing connection status / enums

@scottf scottf changed the title fix test failing because of timeout but aren't testing timing fix test failing because of timeout that aren't testing timing Dec 13, 2020
}

handler.waitForStatusChange(400, TimeUnit.MILLISECONDS);
try { nc.flush(Duration.ofMillis(250)); } catch (Exception exp) { /* ignored */ }
Copy link
Contributor Author

@scottf scottf Dec 13, 2020

Choose a reason for hiding this comment

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

Increased flush wait from 100 to 250 as it was flapping here. The test is about something else so this just needs to always work.

@scottf scottf marked this pull request as ready for review December 13, 2020 20:23
assertTrue(one == 10, "always got one");
assertTrue(two == 0, "never got two");
assertEquals(one, 10, "always got one");
assertEquals(two, 0, "never got two");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

nitty for sure, but again how the assertions were designed.

Copy link
Member

Choose a reason for hiding this comment

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

I see linter complaints about these... thanks.

} catch (Exception exp) {

}
sleep(5000); // No server at this point, let it fail and try to start over
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sleep macro just cleaner.

Copy link
Member

Choose a reason for hiding this comment

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

could be a bit more deterministic and use options.getConnectionTimeout() + 100 in case the default timeout changes.

}
}
}

@Test
public void testConnectExceptionHasURLS() throws IOException, InterruptedException {
public void testConnectExceptionHasURLS() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

exception was never thrown


handler.waitForStatusChange(1000, TimeUnit.MILLISECONDS);
Copy link
Contributor Author

@scottf scottf Dec 14, 2020

Choose a reason for hiding this comment

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

After I fixed that one, this one flapped.


nc = handler.getConnection(); // will be disconnected, but should be there
assertNotNull(nc);

handler.prepForStatusChange(Events.RECONNECTED);
try (NatsTestServer ts = new NatsTestServer(port, false)) {
handler.waitForStatusChange(5, TimeUnit.SECONDS);
assertTrue(Connection.Status.CONNECTED == nc.getStatus(), "Connected Status");
waitThenAssertConnected(nc, handler);
Copy link
Contributor Author

@scottf scottf Dec 14, 2020

Choose a reason for hiding this comment

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

This macro fixed the flappers that didn't allow enough time for the connection. With the macro it's consistent. Only used in tests where they are not testing the connection itself, but using the connection to test something. This version of the macro waits up to 5 seconds. There is another version that you can specify the wait.

}
assertTrue(Connection.Status.CONNECTED == nc.getStatus(), "Connected Status");

sleep(1000);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

more flapping. again not the point of the test

d.subscribe("dispatchSubject");

handler.prepForStatusChange(Events.RECONNECTED);

try (NatsTestServer ts = new NatsTestServer(port, false)) {
handler.waitForStatusChange(400, TimeUnit.MILLISECONDS);
assertTrue(Connection.Status.CONNECTED == nc.getStatus(), "Connected Status");
waitThenAssertConnected(nc, handler);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not enough time to ensure connect. use macro since this not the point of the test

} finally {
nc.close();
assertTrue(Connection.Status.CLOSED == nc.getStatus(), "Closed Status");
closeThenAssertClosed(nc);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed it was the same thing over and over with no variation. "Macros" aren't really a java thing, just something I like. I think they add description to the tests and simplify routine scaffolding code.

handler.prepForStatusChange(Events.CLOSED);
}

flushAndWait(nc, handler);
assertTrue(Connection.Status.CLOSED == nc.getStatus(), "Closed Status");
assertSame(Connection.Status.CLOSED, nc.getStatus(), "Closed Status");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

assertSame is recommended for enum, even though it does the exact same thing. Intellij called it "simplify"

Copy link
Member

@ColinSullivan1 ColinSullivan1 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

One small ask - can you amend your last commit with -s to sign?

@ColinSullivan1 ColinSullivan1 merged commit 0cd49ec into nats-io:master Dec 14, 2020
@scottf scottf deleted the fix-tests-timeouts branch December 20, 2020 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants