Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions example/integration_test/t03_navigation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ void main() {
await GoogleMapsNavigator.stopGuidance();
}

GoogleMapsNavigator.setOnArrivalListener(onArrivalEvent);
final StreamSubscription<OnArrivalEvent> onArrivalSubscription =
GoogleMapsNavigator.setOnArrivalListener(onArrivalEvent);

/// Simulate location and test it.
await setSimulatedUserLocationWithCheck(
Expand Down Expand Up @@ -132,9 +133,11 @@ void main() {
expectSync(msg.location.longitude, lessThanOrEqualTo(endLng + tolerance));
}

await GoogleMapsNavigator.setRoadSnappedLocationUpdatedListener(
onLocationEvent,
);
final StreamSubscription<RoadSnappedLocationUpdatedEvent>
roadSnappedSubscription =
await GoogleMapsNavigator.setRoadSnappedLocationUpdatedListener(
onLocationEvent,
);

/// Start simulation.
await GoogleMapsNavigator.simulator.simulateLocationsAlongExistingRoute();
Expand All @@ -143,6 +146,9 @@ void main() {
await hasArrived.future;
expect(await GoogleMapsNavigator.isGuidanceRunning(), false);

// Cancel subscriptions before cleanup
await onArrivalSubscription.cancel();
await roadSnappedSubscription.cancel();
await GoogleMapsNavigator.cleanup();
});

Expand Down Expand Up @@ -228,7 +234,8 @@ void main() {
}
}

GoogleMapsNavigator.setOnArrivalListener(onArrivalEvent);
final StreamSubscription<OnArrivalEvent> onArrivalSubscription =
GoogleMapsNavigator.setOnArrivalListener(onArrivalEvent);

/// Simulate location and test it.
await setSimulatedUserLocationWithCheck(
Expand Down Expand Up @@ -291,9 +298,11 @@ void main() {
}
}

await GoogleMapsNavigator.setRoadSnappedLocationUpdatedListener(
onLocationEvent,
);
final StreamSubscription<RoadSnappedLocationUpdatedEvent>
roadSnappedSubscription =
await GoogleMapsNavigator.setRoadSnappedLocationUpdatedListener(
onLocationEvent,
);

/// Start simulation.
$.log('Starting simulation with speedMultiplier: 5');
Expand All @@ -311,6 +320,9 @@ void main() {
await navigationFinished.future;
expect(await GoogleMapsNavigator.isGuidanceRunning(), false);

// Cancel subscriptions before cleanup
await onArrivalSubscription.cancel();
await roadSnappedSubscription.cancel();
await GoogleMapsNavigator.cleanup();
},
variant: multipleDestinationsVariants,
Expand Down Expand Up @@ -471,8 +483,8 @@ void main() {
await finishTest.future;
$.log('Loop with simulator$loopIteration finished.');

await GoogleMapsNavigator.cleanup();
await subscription.cancel();
await GoogleMapsNavigator.cleanup();
await $.pumpAndSettle();
}
});
Expand Down Expand Up @@ -630,7 +642,13 @@ void main() {
expect(GoogleMapsNavigator.isGuidanceRunning(), false);
}

GoogleMapsNavigator.setOnArrivalListener(onArrivalEvent);
final StreamSubscription<OnArrivalEvent> onArrivalSubscription =
GoogleMapsNavigator.setOnArrivalListener(onArrivalEvent);

// The subscription will be automatically cleaned up when the test ends.
addTearDown(() async {
await onArrivalSubscription.cancel();
});
});

patrol('Test error during navigation if no network connection', (
Expand Down Expand Up @@ -753,7 +771,8 @@ void main() {
hasArrived.complete();
}

GoogleMapsNavigator.setOnArrivalListener(onArrivalEvent);
final StreamSubscription<OnArrivalEvent> onArrivalSubscription =
GoogleMapsNavigator.setOnArrivalListener(onArrivalEvent);

/// Simulate location (1298 California St)
const double tolerance = 0.001;
Expand Down Expand Up @@ -850,6 +869,9 @@ void main() {

/// Check that the last segment is near target destination.
expect(endSegment!.destinationLatLng.longitude, closeTo(-122.412, 0.002));

// Cancel subscription before test ends
await onArrivalSubscription.cancel();
});

patrol('Test that the navigation session is attached to existing map', (
Expand Down
78 changes: 45 additions & 33 deletions example/integration_test/t09_isolates_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +32,56 @@ void main() {
final RootIsolateToken rootIsolateToken = RootIsolateToken.instance!;
const int numIsolates = 3;
final List<ReceivePort> receivePorts = [];
final List<Isolate> isolates = [];

for (int i = 0; i < numIsolates; i++) {
final ReceivePort receivePort = ReceivePort();
receivePorts.add(receivePort);
try {
for (int i = 0; i < numIsolates; i++) {
final ReceivePort receivePort = ReceivePort();
receivePorts.add(receivePort);

await Isolate.spawn(
_isolateVersionCheckMain,
_IsolateData(
rootIsolateToken: rootIsolateToken,
sendPort: receivePort.sendPort,
),
);
}
final Isolate isolate = await Isolate.spawn(
_isolateVersionCheckMain,
_IsolateData(
rootIsolateToken: rootIsolateToken,
sendPort: receivePort.sendPort,
),
);
isolates.add(isolate);
}

final List<_IsolateResult> results = [];
for (final receivePort in receivePorts) {
final dynamic result = await receivePort.first;
expect(result, isA<_IsolateResult>());
results.add(result as _IsolateResult);
}
final List<_IsolateResult> results = [];
for (final receivePort in receivePorts) {
final dynamic result = await receivePort.first;
expect(result, isA<_IsolateResult>());
results.add(result as _IsolateResult);
}

for (int i = 0; i < results.length; i++) {
expect(
results[i].error,
isNull,
reason: 'Isolate $i should not throw an error',
);
expect(results[i].version, isNotNull);
expect(results[i].version!.length, greaterThan(0));
}
for (int i = 0; i < results.length; i++) {
expect(
results[i].error,
isNull,
reason: 'Isolate $i should not throw an error',
);
expect(results[i].version, isNotNull);
expect(results[i].version!.length, greaterThan(0));
}

final String firstVersion = results[0].version!;
for (int i = 1; i < results.length; i++) {
expect(
results[i].version,
equals(firstVersion),
reason: 'All isolates should return the same SDK version',
);
final String firstVersion = results[0].version!;
for (int i = 1; i < results.length; i++) {
expect(
results[i].version,
equals(firstVersion),
reason: 'All isolates should return the same SDK version',
);
}
} finally {
// Clean up resources
for (final receivePort in receivePorts) {
receivePort.close();
}
for (final isolate in isolates) {
isolate.kill(priority: Isolate.immediate);
}
}
},
);
Expand Down
Loading