Skip to content

Commit

Permalink
Revert test
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 13, 2024
1 parent e4a60f7 commit 5d45a52
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class SimplexTransferListenerTest {
@Test
void cancellation() {
void cancellation() throws InterruptedException {
TransferListener delegate = new TransferListener() {
@Override
public void transferInitiated(TransferEvent event) throws TransferCancelledException {
Expand Down Expand Up @@ -66,12 +66,12 @@ public void transferFailed(TransferEvent event) {}

TransferResource resource =
new TransferResource(null, null, "http://maven.org/test/test-resource", new File("file"), null);
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(h -> false);
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(h -> false); // no close handle

// Send initiated event and make it the "last" event to force blocking
// for technical reasons we cannot throw here, even if delegate does cancel transfer
listener.transferInitiated(event(session, resource, TransferEvent.EventType.INITIATED));
// Use transferFailed as a sentinel to ensure the previous event was processed
listener.transferFailed(event(session, resource, TransferEvent.EventType.FAILED));

Thread.sleep(500); // to make sure queue is processed, cancellation applied

// subsequent call will cancel
assertThrows(
Expand All @@ -80,7 +80,7 @@ public void transferFailed(TransferEvent event) {}
}

@Test
void handlesAbsentTransferSource() throws TransferCancelledException {
void handlesAbsentTransferSource() throws InterruptedException, TransferCancelledException {
TransferResource resource = new TransferResource(null, null, "http://maven.org/test/test-resource", null, null);

RepositorySystemSession session = Mockito.mock(RepositorySystemSession.class);
Expand All @@ -95,9 +95,10 @@ void handlesAbsentTransferSource() throws TransferCancelledException {
listener.transferInitiated(transferInitiatedEvent);
listener.transferStarted(transferStartedEvent);
listener.transferProgressed(transferProgressedEvent);
// The succeeded event will be the last one and will block until processed
listener.transferSucceeded(transferSucceededEvent);

Thread.sleep(500); // to make sure queue is processed, cancellation applied

Mockito.verify(delegate).transferInitiated(transferInitiatedEvent);
Mockito.verify(delegate).transferStarted(transferStartedEvent);
Mockito.verify(delegate).transferProgressed(transferProgressedEvent);
Expand Down

0 comments on commit 5d45a52

Please sign in to comment.