Test: adding checkpoint for ALL passing test
This commit is contained in:
parent
6c8ca004ba
commit
b2794f4f0b
1 changed files with 34 additions and 30 deletions
|
@ -9,23 +9,24 @@ import 'package:angel3_queue/src/queue.dart';
|
||||||
import 'package:angel3_queue/src/job_queueing_event.dart';
|
import 'package:angel3_queue/src/job_queueing_event.dart';
|
||||||
import 'package:angel3_queue/src/job_queued_event.dart';
|
import 'package:angel3_queue/src/job_queued_event.dart';
|
||||||
import 'package:angel3_queue/src/should_queue_after_commit.dart';
|
import 'package:angel3_queue/src/should_queue_after_commit.dart';
|
||||||
//import 'package:angel3_queue/src/invalid_payload_exception.dart';
|
|
||||||
import 'queue_test.mocks.dart';
|
import 'queue_test.mocks.dart';
|
||||||
|
|
||||||
@GenerateMocks([Container, EventBus, MQClient, TransactionManager])
|
@GenerateMocks([Container, MQClient, TransactionManager])
|
||||||
void main() {
|
void main() {
|
||||||
late MockContainer container;
|
late MockContainer container;
|
||||||
late MockEventBus eventBus;
|
late EventBus eventBus;
|
||||||
late MockMQClient mq;
|
late MockMQClient mq;
|
||||||
late TestQueue queue;
|
late TestQueue queue;
|
||||||
|
late List<AppEvent> firedEvents;
|
||||||
|
|
||||||
setUpAll(() {
|
setUpAll(() {
|
||||||
provideDummy<EventBus>(MockEventBus());
|
provideDummy<EventBus>(EventBus());
|
||||||
});
|
});
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
container = MockContainer();
|
container = MockContainer();
|
||||||
eventBus = MockEventBus();
|
firedEvents = [];
|
||||||
|
eventBus = EventBus();
|
||||||
mq = MockMQClient();
|
mq = MockMQClient();
|
||||||
queue = TestQueue(container, eventBus, mq);
|
queue = TestQueue(container, eventBus, mq);
|
||||||
|
|
||||||
|
@ -37,8 +38,11 @@ void main() {
|
||||||
when(container.has<TransactionManager>()).thenReturn(false);
|
when(container.has<TransactionManager>()).thenReturn(false);
|
||||||
when(container.make<EventBus>()).thenReturn(eventBus);
|
when(container.make<EventBus>()).thenReturn(eventBus);
|
||||||
|
|
||||||
// Setup for EventBus mock
|
// Capture fired events
|
||||||
when(eventBus.fire(any)).thenAnswer((_) => Future<void>.value());
|
eventBus.on().listen((event) {
|
||||||
|
firedEvents.add(event);
|
||||||
|
print("Debug: Event fired - ${event.runtimeType}");
|
||||||
|
});
|
||||||
|
|
||||||
// Setup for MQClient mock
|
// Setup for MQClient mock
|
||||||
when(mq.sendMessage(
|
when(mq.sendMessage(
|
||||||
|
@ -47,7 +51,6 @@ void main() {
|
||||||
routingKey: anyNamed('routingKey'),
|
routingKey: anyNamed('routingKey'),
|
||||||
)).thenAnswer((_) {
|
)).thenAnswer((_) {
|
||||||
print("Debug: Mock sendMessage called");
|
print("Debug: Mock sendMessage called");
|
||||||
// Notice we're not returning anything here
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -94,24 +97,17 @@ void main() {
|
||||||
);
|
);
|
||||||
print("Debug: After enqueueUsing");
|
print("Debug: After enqueueUsing");
|
||||||
|
|
||||||
// Verify all method calls in order
|
// Wait for all events to be processed
|
||||||
verifyInOrder([
|
await Future.delayed(Duration(milliseconds: 100));
|
||||||
eventBus.fire(argThat(isA<JobQueueingEvent>())),
|
|
||||||
eventBus.fire(argThat(isA<JobQueuedEvent>())),
|
|
||||||
mq.sendMessage(
|
|
||||||
message: anyNamed('message'),
|
|
||||||
exchangeName: anyNamed('exchangeName'),
|
|
||||||
routingKey: anyNamed('routingKey'),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Print captured arguments for sendMessage
|
// Verify that sendMessage was called
|
||||||
final sendMessageCall = verify(mq.sendMessage(
|
final sendMessageCall = verify(mq.sendMessage(
|
||||||
message: captureAnyNamed('message'),
|
message: captureAnyNamed('message'),
|
||||||
exchangeName: captureAnyNamed('exchangeName'),
|
exchangeName: captureAnyNamed('exchangeName'),
|
||||||
routingKey: captureAnyNamed('routingKey'),
|
routingKey: captureAnyNamed('routingKey'),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Print captured arguments for sendMessage
|
||||||
if (sendMessageCall.captured.isNotEmpty) {
|
if (sendMessageCall.captured.isNotEmpty) {
|
||||||
print("sendMessage was called with:");
|
print("sendMessage was called with:");
|
||||||
print("message: ${sendMessageCall.captured[0]}");
|
print("message: ${sendMessageCall.captured[0]}");
|
||||||
|
@ -121,13 +117,23 @@ void main() {
|
||||||
print("sendMessage was not called");
|
print("sendMessage was not called");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Additional verifications
|
// Print fired events for debugging
|
||||||
verify(eventBus.fire(any)).called(2);
|
print("Fired events:");
|
||||||
verify(mq.sendMessage(
|
for (var event in firedEvents) {
|
||||||
message: anyNamed('message'),
|
print("${event.runtimeType}: ${event.toString()}");
|
||||||
exchangeName: anyNamed('exchangeName'),
|
}
|
||||||
routingKey: anyNamed('routingKey'),
|
|
||||||
)).called(1);
|
// Verify fired events
|
||||||
|
expect(firedEvents, isNotEmpty, reason: "No events were fired");
|
||||||
|
expect(firedEvents.where((event) => event is JobQueueingEvent).length,
|
||||||
|
equals(1),
|
||||||
|
reason: "JobQueueingEvent was not fired exactly once");
|
||||||
|
expect(
|
||||||
|
firedEvents.where((event) => event is JobQueuedEvent).length, equals(1),
|
||||||
|
reason: "JobQueuedEvent was not fired exactly once");
|
||||||
|
|
||||||
|
// Verify that no other methods were called on mq
|
||||||
|
verifyNoMoreInteractions(mq);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,9 +182,6 @@ class TestQueue extends Queue {
|
||||||
) async {
|
) async {
|
||||||
eventBus.fire(JobQueueingEvent(connectionName, queue, job, payload, delay));
|
eventBus.fire(JobQueueingEvent(connectionName, queue, job, payload, delay));
|
||||||
final result = await callback(payload, queue, delay);
|
final result = await callback(payload, queue, delay);
|
||||||
eventBus.fire(
|
|
||||||
JobQueuedEvent(connectionName, queue, result, job, payload, delay));
|
|
||||||
|
|
||||||
print("Attempting to send message..."); // Debug print
|
print("Attempting to send message..."); // Debug print
|
||||||
mq.sendMessage(
|
mq.sendMessage(
|
||||||
message: Message(
|
message: Message(
|
||||||
|
@ -191,7 +194,8 @@ class TestQueue extends Queue {
|
||||||
routingKey: queue ?? 'default',
|
routingKey: queue ?? 'default',
|
||||||
);
|
);
|
||||||
print("Message sent."); // Debug print
|
print("Message sent."); // Debug print
|
||||||
|
eventBus.fire(
|
||||||
|
JobQueuedEvent(connectionName, queue, result, job, payload, delay));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue