use of org.eclipse.n4js.tester.events.SessionFailedEvent in project n4js by eclipse.
the class TestEventQueue method assertFailed.
/**
* Asserts that the underlying queue represents a session failure as its tail element.
*
* @param sessionId
* the session that has to be failed.
*/
public void assertFailed(final String sessionId) {
assertNotNull("Queue was not initialized. One should call #init(int) before invoking #assertEquals()", latch);
try {
latch.await(20L, SECONDS);
unregisterSupplier.get();
} catch (final InterruptedException e) {
throw new AssertionError("Time outed while waiting to receive all expected test events.", e);
}
final String expectedMessage = new SessionFailedEvent(sessionId).toString();
if (events.isEmpty()) {
fail("Expected to have '" + expectedMessage + "' as the session failed event among events but event queue was empty.");
}
final Collection<String> eventsForSession = events.get(sessionId);
if (!eventsForSession.contains(expectedMessage)) {
fail("Expected to have '" + expectedMessage + "' as the session failed event among events. Was:\n" + toString(eventsForSession));
}
}
use of org.eclipse.n4js.tester.events.SessionFailedEvent in project n4js by eclipse.
the class TestResultsView method notifyTestEvent.
/**
* Update UI according to given {@link TestEvent}.
*/
public void notifyTestEvent(TestEvent event) {
if (event instanceof SessionStartedEvent) {
// ignore
} else if (event instanceof TestStartedEvent) {
notifyTestCaseStarted(new ID(((TestStartedEvent) event).getTestId()));
} else if (event instanceof TestEndedEvent) {
final TestEndedEvent teev = (TestEndedEvent) event;
notifyTestCaseEnded(new ID(teev.getTestId()), teev.getResult());
} else if (event instanceof SessionEndedEvent) {
// event received from client side
notifySessionEnded(new ID(event.getSessionId()));
} else if (event instanceof SessionFinishedEvent) {
// server completed test session SUCCESS
// ignore
} else if (event instanceof SessionFailedEvent) {
// server completed test session FAILURE
// ignore
} else {
// ignore all other events (e.g. TestPingedEvent)
}
}
use of org.eclipse.n4js.tester.events.SessionFailedEvent in project n4js by eclipse.
the class TestFsmRegistryImpl method receivedTestEvent.
/**
* Percepts any {@link TestEvent test event} and delegates it to the corresponding tester finite state machine.
*
* @param event
* the received event that will be processed.
*/
@Subscribe
@AllowConcurrentEvents
public void receivedTestEvent(final TestEvent event) {
if (event instanceof SessionFailedEvent && ((SessionFailedEvent) event).getComment().isPresent()) {
LOGGER.error("Received event: " + event + ". Reason: " + ((SessionFailedEvent) event).getComment().get());
} else {
if (debugEnabled) {
LOGGER.debug("Received event: " + event);
}
}
final String sessionId = event.getSessionId();
if (event instanceof SessionStartedEvent) {
if (!isSessionExist(sessionId)) {
registerFsm(sessionId);
}
getSession(sessionId).startSession(sessionId);
} else if (event instanceof SessionPingedEvent) {
final long timeout = ((SessionPingedEvent) event).getTimeout();
getSession(sessionId).pingSession(sessionId, timeout);
} else if (event instanceof SessionEndedEvent) {
final TestFsm fsm = getSession(sessionId).endSession(sessionId);
if (fsm instanceof TestFsmImpl && !((TestFsmImpl) fsm).isFailed()) {
if (!treeRegistry.validateTestTree(sessionId)) {
((TestFsmImpl) fsm).fail("Test session failed due to invalid final state of the test tree. " + "There are test cases without any test results after receiving session ended event.");
return;
}
}
bus.post(new SessionFinishedEvent(sessionId));
} else if (event instanceof SessionFailedEvent) {
treeRegistry.purgeTestTree(sessionId);
unregisterFsm(sessionId);
} else if (event instanceof SessionFinishedEvent) {
unregisterFsm(sessionId);
} else if (event instanceof TestStartedEvent) {
final String testId = ((TestStartedEvent) event).getTestId();
final long timeout = ((TestStartedEvent) event).getTimeout();
getSession(sessionId).startTest(testId, timeout);
} else if (event instanceof TestPingedEvent) {
final long timeout = ((TestPingedEvent) event).getTimeout();
final String testId = ((TestPingedEvent) event).getTestId();
getSession(sessionId).pingTest(testId, timeout);
} else if (event instanceof TestEndedEvent) {
final TestEndedEvent testEndedEvent = (TestEndedEvent) event;
final String testId = testEndedEvent.getTestId();
final TestFsm fsm = getSession(sessionId).endTest(testId);
if (fsm instanceof TestFsmImpl && !((TestFsmImpl) fsm).isFailed()) {
treeRegistry.putTestResult(sessionId, testId, testEndedEvent.getResult());
}
} else {
LOGGER.error("Unexpected test event: " + event);
}
}
use of org.eclipse.n4js.tester.events.SessionFailedEvent in project n4js by eclipse.
the class TestEventQueueTest method testAssertFailedHappyPath.
/**
*/
@Test
public void testAssertFailedHappyPath() {
final String sessionId = "sessionId";
queue.init(2);
post(new SessionStartedEvent(sessionId));
post(new SessionFailedEvent(sessionId));
queue.assertFailed(sessionId);
}
Aggregations