Skip to content

Make some of the c.g.g.view.client.*SelectionModelTest tests async.#10365

Open
niloc132 wants to merge 1 commit into
gwtproject:mainfrom
niloc132:9622-selectionmodel-test-cherrypick
Open

Make some of the c.g.g.view.client.*SelectionModelTest tests async.#10365
niloc132 wants to merge 1 commit into
gwtproject:mainfrom
niloc132:9622-selectionmodel-test-cherrypick

Conversation

@niloc132

@niloc132 niloc132 commented Jul 9, 2026

Copy link
Copy Markdown
Member

SelectionModel fires selection events using a finally command and some tests using SelectionChangeEvent.Handler were not async. In addition these tests had an implementation that let the test fail (but ANT never noticed because tests were sync).

This CL makes sure all tests using SelectionChangeEvent.Handler are async and updates implementation slightly to correclty assert event behavior.

Previously submitted as https://gwt-review.googlesource.com/c/gwt/+/21060.

Fixes #9622

SelectionModel fires selection events using a finally command and
some tests using SelectionChangeEvent.Handler were not async.
In addition these tests had an implementation that let the test fail
(but ANT never noticed because tests were sync).

This CL makes sure all tests using SelectionChangeEvent.Handler are
async and updates implementation slightly to correclty assert event
behavior.

Bug: gwtproject#9622
Bug-Link: gwtproject#9622
Change-Id: I66ba1170d2a1335d3ad921346017b5b5bc1accf8
@niloc132 niloc132 added this to the 2.14 milestone Jul 9, 2026
@niloc132 niloc132 added the ready This PR has been reviewed by a maintainer and is ready for a CI run. label Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here the AssertOneSelectionChangeEventOnlyHandler is still listening, so it would fail in case another event is fired. We shouldn't need to ad a second handler for that.

@jnehlmeier jnehlmeier Jul 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

MockSelectionChangeHandler requires you to call assertEventFired and it will clear its internal state after that call, so you always have to do event -> check -> event -> check. MockSelectionChangeHandler will fail if it sees a second event in a row without calling assertEventFired in between.

If we would remove the failing handler then the first model.setSelected() following this line would only be recorded and only the second call would trigger the exception in MockSelectionChangeHandler because you haven't called assertEventFired in between two events. That makes the test a little imprecise. If you would want to call assertEventFired in between then it must happen async again which bloats the code.

The failing handler exists to simplify the logic and to make sure that the first additional event already fails the test and not the second.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Again, this handler may not be needed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Again, this handler may not be needed.

@zbynek zbynek left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The code looks correct, but some of the handlers are not needed as far as I understand (see inline comments).
Alternatively, instead of two types of mock handlers it should be possible to have one type that counts events and let the test make assertions on those counts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready This PR has been reviewed by a maintainer and is ready for a CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Various broken SelectionModel tests in com.google.gwt.view.client

3 participants