{
SqlTask sqlTask = createInitialTask();
updateTask(sqlTask, EMPTY_SOURCES, INITIAL_EMPTY_OUTPUT_BUFFERS.withBuffer(OUT, new UnpartitionedPagePartitionFunction()));
ListenableFuture<BufferResult> bufferResult = sqlTask.getTaskResults(OUT, 0, new DataSize(1, MEGABYTE));
assertFalse(bufferResult.isDone());
TaskState taskState = sqlTask.getTaskInfo().getState();
sqlTask.failed(new Exception("test"));
assertEquals(sqlTask.getTaskInfo(taskState).get(200, MILLISECONDS).getState(), TaskState.FAILED);
// buffer will not be closed by fail event. event is async so wait a bit for event to fire
try {
assertTrue(bufferResult.get(200, MILLISECONDS).isBufferClosed());
fail("expected TimeoutException");
}
catch (TimeoutException expected) {
}
assertFalse(sqlTask.getTaskResults(OUT, 0, new DataSize(1, MEGABYTE)).isDone());
}