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

[sinttest] Additional tests covering s7 of XEP-0045 #482

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

Fishbowler
Copy link
Member

Follows #475, #477 and #478. Draft until they're merged.

@guusdk guusdk force-pushed the xep-0045-coverage-part4 branch 2 times, most recently from 731bb66 to 36afd84 Compare July 8, 2021 13:23
@evdherberg
Copy link

This morning I rebased this branch to Fishbowler:xep-0045-coverage-part3

@evdherberg
Copy link

@Flowdalic My rebase may have cleared out your earlier comments, which is unfortunate. I remember one about using enums, probably for error types. Do you remember the other one?

@Flowdalic
Copy link
Member

The are still at the commit where I made them (which was "dropped" by you force pushing): 65dee17

@Fishbowler Fishbowler force-pushed the xep-0045-coverage-part4 branch 2 times, most recently from e8ac665 to 02b88f3 Compare October 16, 2021 15:10
Copy link
Member

@Flowdalic Flowdalic left a comment

Choose a reason for hiding this comment

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

Not directly related to this PR, but the following pattern repeats over and over in the MUC integration tests

        EntityBareJid mucAddress = getRandomRoom("smack-inttest-discoinfo");
        MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
        createMuc(mucAsSeenByOne, Resourcepart.from("one-" + randomString));

which suggests that we can add a convenience method to reduce the boilerplate code. I thnk of

public MultiUserChat createMuc(MultiUserChatManager manager, String roomnameComponent) {
…
}

which, for example, determines the nickname prefix (one-, two-) by the provided manager.

Note that I was not able to review the complete PR yet. But I'd like to provide my feedback early, even if it is incomplete.

messageReflectionSyncPoint.waitForResult(timeout);

final ResultSyncPoint<String, Exception> subjectResultSyncPoint = new ResultSyncPoint<>();
List<Object> results = new ArrayList<Object>();
Copy link
Member

Choose a reason for hiding this comment

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

Did you check that no concurrent access to this data structure happens?

Copy link
Member Author

Choose a reason for hiding this comment

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

For the ArrayList?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

@Fishbowler Fishbowler force-pushed the xep-0045-coverage-part4 branch 3 times, most recently from d4141f0 to 112004d Compare October 19, 2021 19:01
@Fishbowler
Copy link
Member Author

Not directly related to this PR, but the following pattern repeats over and over in the MUC integration tests

        EntityBareJid mucAddress = getRandomRoom("smack-inttest-discoinfo");
        MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
        createMuc(mucAsSeenByOne, Resourcepart.from("one-" + randomString));

which suggests that we can add a convenience method to reduce the boilerplate code. I thnk of

public MultiUserChat createMuc(MultiUserChatManager manager, String roomnameComponent) {
…
}

which, for example, determines the nickname prefix (one-, two-) by the provided manager.

I've had a play with this, but we regularly need mucAsSeenByOne later in the test. You could wrap the first two lines and return the MultiUserChat, but you couldn't use it if you needed a mucAsSeenByTwo, or you'd need to get the JID from mucAsSeenByOne, and we'd save no lines and reduce complexity even less.

wait(deadline - now);
}
}
if (expectedResultCount <= results.size()) {
Copy link
Member

Choose a reason for hiding this comment

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

This duplicated code can be removed by slightly changing the logic of this method.

Copy link
Member

Choose a reason for hiding this comment

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

What duplication are you referring to here? I don't see how we can reduce the check if the expected count matches the result count, as that needs to happen both before and after waiting. (This mimics what's implemented in ResultSyncPoint).

Copy link
Member

Choose a reason for hiding this comment

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

First, I just noticed that this method directly returns results. I am not sure if this is sensible, given that results could potentially concurrently be modified after it was returned. Therefore I would suggest returning a copy, where the copy is made while the monitor lock is held.

I suggest the following, IMHO more idiomatic, implementation for the method. Also note that it follows a more defensive approach, where the exception is thrown, even if all results are there. If there is a compelling reason to swap this, then I could consider that. (It would also be made configurable)

    public synchronized List<R> waitForResults(long timeout) throws E, InterruptedException, TimeoutException {
        long now = System.currentTimeMillis();
        final long deadline = now + timeout;
        while (results.size <= expectedResultSize && !exception && now < deadline) {
              wait(deadline - now);
              now = System.currentTimeMillis();
        }
         if (now >= deadline) throw new TimeoutException("Timeout waiting " + timeout + " millis");
         if (exception != null) throw exception;
         return results; // TODO: Copy results
    }

@Flowdalic
Copy link
Member

I've had a play with this, but we regularly need mucAsSeenByOne later in the test. You could wrap the first two lines and return the MultiUserChat, but you couldn't use it if you needed a mucAsSeenByTwo, or you'd need to get the JID from mucAsSeenByOne, and we'd save no lines and reduce complexity even less.

How about?

MultiUserChat mucAsSeenByOne = createMuc(mucManagerOne, "smack-inttest-discoinfo");
MultiUserChat musAsSeenByTwo = getMuc(mucManagerTwo, mucAsSeenByOne);

@guusdk guusdk marked this pull request as ready for review July 31, 2022 08:37
@guusdk guusdk requested a review from Flowdalic July 31, 2022 11:34
@guusdk guusdk changed the title Additional tests covering s7 of XEP-0045 [sinttest] Additional tests covering s7 of XEP-0045 Apr 12, 2024
@guusdk
Copy link
Member

guusdk commented Apr 16, 2024

Not directly related to this PR, but the following pattern repeats over and over in the MUC integration tests

        EntityBareJid mucAddress = getRandomRoom("smack-inttest-discoinfo");
        MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
        createMuc(mucAsSeenByOne, Resourcepart.from("one-" + randomString));

which suggests that we can add a convenience method to reduce the boilerplate code. I thnk of

public MultiUserChat createMuc(MultiUserChatManager manager, String roomnameComponent) {
…
}

which, for example, determines the nickname prefix (one-, two-) by the provided manager.

I've tried doing this, but it doesn't really work out most of the time. Many of the instance references that are removed by such a method are needed elsewhere in the unit test implementation (for example in the assertions) making the replacement effort rather moot.

@guusdk
Copy link
Member

guusdk commented Apr 16, 2024

@Flowdalic - is there anything to be done to 'fix' the coveralls check (that's now reporting failure)?

@guusdk
Copy link
Member

guusdk commented Apr 16, 2024

@Flowdalic - is there anything to be done to 'fix' the coveralls check (that's now reporting failure)?

I've now added a new unit test for the MultiResultSyncPoint util that was added in this PR. Hopefully, that makes the test coverage check happy again.

@guusdk guusdk force-pushed the xep-0045-coverage-part4 branch 2 times, most recently from 32776d3 to 7196c8b Compare April 16, 2024 14:56
wait(deadline - now);
}
}
if (expectedResultCount <= results.size()) {
Copy link
Member

Choose a reason for hiding this comment

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

First, I just noticed that this method directly returns results. I am not sure if this is sensible, given that results could potentially concurrently be modified after it was returned. Therefore I would suggest returning a copy, where the copy is made while the monitor lock is held.

I suggest the following, IMHO more idiomatic, implementation for the method. Also note that it follows a more defensive approach, where the exception is thrown, even if all results are there. If there is a compelling reason to swap this, then I could consider that. (It would also be made configurable)

    public synchronized List<R> waitForResults(long timeout) throws E, InterruptedException, TimeoutException {
        long now = System.currentTimeMillis();
        final long deadline = now + timeout;
        while (results.size <= expectedResultSize && !exception && now < deadline) {
              wait(deadline - now);
              now = System.currentTimeMillis();
        }
         if (now >= deadline) throw new TimeoutException("Timeout waiting " + timeout + " millis");
         if (exception != null) throw exception;
         return results; // TODO: Copy results
    }

@guusdk
Copy link
Member

guusdk commented Apr 26, 2024

Applied review feedback, and squashed ~3 years of commits into one.

Copy link
Member

@Flowdalic Flowdalic left a comment

Choose a reason for hiding this comment

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

One minor thing, not sure why did only noticed it yet.

@guusdk guusdk requested a review from Flowdalic April 30, 2024 07:46
@Flowdalic Flowdalic merged commit 36d6ff2 into igniterealtime:master Apr 30, 2024
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants