-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[grid] Fix flaky event bus tests by dedicated threading, reverting th…
…e polling loop logic and increasing poll timeout (#9383) * [grid] Fix flaky event bus tests by dedicated threading and reverting the polling loop logic. * [grid] Fix error messages for event bus * [grid] Print stacktrace in case of exceptions during eventbus tests * [grid] Split the Eventbus tests into separate test classes * [grid] Closing the context in the ZeroMqTcpTest to see if it helps Co-authored-by: Diego Molina <[email protected]>
- Loading branch information
Showing
5 changed files
with
378 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
java/server/test/org/openqa/selenium/events/EventBusGuavaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.events; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openqa.selenium.events.local.GuavaEventBus; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class EventBusGuavaTest { | ||
private EventBus bus; | ||
|
||
@Before | ||
public void getBus() { | ||
bus = new GuavaEventBus(); | ||
} | ||
|
||
@After | ||
public void closeBus() { | ||
bus.close(); | ||
} | ||
|
||
@Test(timeout = 4000) | ||
public void shouldBeAbleToPublishToAKnownTopic() throws InterruptedException { | ||
EventName cheese = new EventName("cheese"); | ||
Event event = new Event(cheese, null); | ||
|
||
CountDownLatch latch = new CountDownLatch(1); | ||
bus.addListener(new EventListener<>(cheese, Object.class, obj -> latch.countDown())); | ||
bus.fire(event); | ||
latch.await(1, SECONDS); | ||
|
||
assertThat(latch.getCount()).isEqualTo(0); | ||
} | ||
|
||
@Test(timeout = 4000) | ||
public void shouldNotReceiveEventsNotMeantForTheTopic() { | ||
AtomicInteger count = new AtomicInteger(0); | ||
bus.addListener(new EventListener<>(new EventName("peas"), Object.class, obj -> count.incrementAndGet())); | ||
|
||
bus.fire(new Event(new EventName("cheese"), null)); | ||
|
||
assertThat(count.get()).isEqualTo(0); | ||
} | ||
|
||
@Test | ||
public void shouldBeAbleToFireEventsInParallel() throws InterruptedException { | ||
int maxCount = 100; | ||
EventName name = new EventName("cheese"); | ||
|
||
CountDownLatch count = new CountDownLatch(maxCount); | ||
bus.addListener(new EventListener<>(name, Object.class, obj -> count.countDown())); | ||
|
||
ExecutorService executor = Executors.newCachedThreadPool(); | ||
try { | ||
for (int i = 0; i < maxCount; i++) { | ||
executor.submit(() -> bus.fire(new Event(name, ""))); | ||
} | ||
|
||
assertThat(count.await(20, SECONDS)).describedAs(count.toString()).isTrue(); | ||
} finally { | ||
executor.shutdownNow(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.