[ https://issues.apache.org/jira/browse/GEODE-8589?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17212609#comment-17212609 ]
ASF GitHub Bot commented on GEODE-8589: --------------------------------------- upthewaterspout opened a new pull request #5617: URL: https://github.com/apache/geode/pull/5617 Wait for the view to have size 2 instead of asserting it in MembershipIntegrationTest.locatorsStopWaitingForLocatorWaitTimeIfAllLocatorsContacted, because the view is updated asynchronously. Thank you for submitting a contribution to Apache Geode. In order to streamline the review of the contribution we ask you to ensure the following steps have been taken: ### For all changes: - [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message? - [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)? - [ ] Is your initial contribution a single, squashed commit? - [ ] Does `gradlew build` run cleanly? - [ ] Have you written or updated unit tests to verify your changes? - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? ### Note: Please ensure that once the PR is submitted, check Concourse for build issues and submit an update to your PR as soon as possible. If you need help, please send an email to d...@geode.apache.org. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > make locatorsStopWaitingForLocatorWaitTimeIfAllLocatorsContacted test > deterministic > ----------------------------------------------------------------------------------- > > Key: GEODE-8589 > URL: https://issues.apache.org/jira/browse/GEODE-8589 > Project: Geode > Issue Type: Improvement > Components: membership > Reporter: Bill Burcham > Priority: Major > Labels: membership > > A recent commit added a new test: > {{MembershipIntegrationTest.locatorsStopWaitingForLocatorWaitTimeIfAllLocatorsContacted()}} > That's a good test. But it would be better if it ran faster and was less > susceptible to timing issues. The problem is that the logic we are trying to > test, {{GMSJoinLeave.leave()}} uses {{System.currentTimeMillis()}} to get the > current time and it uses {{Thread.sleep()}} to sleep: > {code:java} > long now = System.currentTimeMillis(); > ... > if (state.joinedMembersContacted <= 0 && ((now >= > locatorGiveUpTime && > tries >= minimumRetriesBeforeBecomingCoordinator) || > state.locatorsContacted >= locators.size())) { > ... > if (System.currentTimeMillis() > giveupTime) { > break; > } > ... > Thread.sleep(retrySleep); > ... > giveupTime = System.currentTimeMillis() + timeout; > ... > if (!this.isJoined) { > logger.debug("giving up attempting to join the distributed system > after " > + (System.currentTimeMillis() - startTime) + "ms"); > } > ... > if (!this.isJoined && state.hasContactedAJoinedLocator) { > throw new MemberStartupException("Unable to join the distributed > system in " > + (System.currentTimeMillis() - startTime) + "ms"); > } > {code} > The opportunity is to _inject_ objects that handle these two functions (time > keeping and sleeping). This will enable us to artifically control these in > our test! Sleeping doesn't have to take any time at all. And we can make time > pass as quickly as we want to. > For an example of how this can be done, see [PR > #5422|https://github.com/apache/geode/pull/5422] for GEODE-6950. > This particular test > ({{locatorsStopWaitingForLocatorWaitTimeIfAllLocatorsContacted()}}) is a > little bit more involved than that one in that more objects are involved. In > addition to {{GMSJoinLeave}}, other classes involved in the test also need > current time and need to sleep. > When this ticket is complete: > * functional interfaces {{MillisecondProvider}} and {{Sleeper}}, currently > defined inside {{PrimaryHandler}} will be moved higher in the (internal) > hierarchy for use by other membership classes > * {{GMSJoinLeave}} will take a {{MillisecondProvider}} and {{Sleeper}} in its > constructor and will delegate to those instead of calling > {{System.currentTimeMillis()}} and {{Thread.sleep()}} directly > * TBD other classes may require injection of {{MillisecondProvider}} and > {{Sleeper}} > * TBD other changes may be necessary in cases where collaborating classes > currently spin up threads or synchronize between threads e.g. calling > {{wait()}} > * {{locatorsStopWaitingForLocatorWaitTimeIfAllLocatorsContacted()}} will no > longer employ {{Thread.sleep()}} nor will it call > {{CompletableFuture.get(long timeout, TimeUnit unit)}}—instead it will > operate deterministically (ideally in the same thread but not necessarily) > with respect to the unit under test. -- This message was sent by Atlassian Jira (v8.3.4#803005)