-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: [native] Fix errors when hot restarted (#86)
* fix: [native] Fix errors when hot restarted
- Loading branch information
1 parent
1d5d8f9
commit ab6260e
Showing
7 changed files
with
131 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
import 'dart:isolate'; | ||
|
||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:iris_method_channel/src/platform/io/iris_event_io.dart'; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
testWidgets('IrisEvent smoke test', (tester) async { | ||
await tester.pumpAndSettle(); | ||
testWidgets( | ||
'IrisEvent smoke test', | ||
(tester) async { | ||
await tester.pumpWidget(Container()); | ||
|
||
IrisEventIO irisEvent = IrisEventIO(); | ||
irisEvent.initialize(); | ||
final testPort = ReceivePort(); | ||
irisEvent.registerEventHandler(testPort.sendPort); | ||
irisEvent.unregisterEventHandler(testPort.sendPort); | ||
irisEvent.onEventPtr; | ||
irisEvent.dispose(); | ||
}); | ||
IrisEventIO irisEvent = IrisEventIO(); | ||
irisEvent.initialize(); | ||
final testPort = ReceivePort(); | ||
irisEvent.registerEventHandler(testPort.sendPort); | ||
irisEvent.unregisterEventHandler(testPort.sendPort); | ||
irisEvent.onEventPtr; | ||
irisEvent.dispose(); | ||
}, | ||
timeout: const Timeout(Duration(minutes: 10)), | ||
); | ||
} |
94 changes: 94 additions & 0 deletions
94
example/integration_test/iris_method_channel_smoke_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import 'dart:isolate'; | ||
import 'dart:ffi' as ffi; | ||
|
||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:iris_method_channel/iris_method_channel.dart'; | ||
import 'package:iris_method_channel/src/platform/io/iris_method_channel_internal_io.dart'; | ||
|
||
class _FakeNativeBindingDelegate extends PlatformBindingsDelegateInterface { | ||
_FakeNativeBindingDelegate(); | ||
|
||
@override | ||
int callApi( | ||
IrisMethodCall methodCall, | ||
IrisApiEngineHandle apiEnginePtr, | ||
IrisApiParamHandle param, | ||
) { | ||
return 0; | ||
} | ||
|
||
@override | ||
IrisEventHandlerHandle createIrisEventHandler( | ||
IrisCEventHandlerHandle eventHandler, | ||
) { | ||
return IrisEventHandlerHandle(ffi.Pointer<ffi.Void>.fromAddress(123456)); | ||
} | ||
|
||
@override | ||
CreateApiEngineResult createApiEngine(List<Object> args) { | ||
return CreateApiEngineResult( | ||
IrisApiEngineHandle(ffi.Pointer<ffi.Void>.fromAddress(100)), | ||
extraData: <String, Object>{'extra_handle': 1000}, | ||
); | ||
} | ||
|
||
@override | ||
void destroyIrisEventHandler( | ||
IrisEventHandlerHandle handler, | ||
) {} | ||
|
||
@override | ||
void destroyNativeApiEngine(IrisApiEngineHandle apiEnginePtr) {} | ||
|
||
@override | ||
void initialize() {} | ||
|
||
@override | ||
Future<CallApiResult> callApiAsync(IrisMethodCall methodCall, | ||
IrisApiEngineHandle apiEnginePtr, IrisApiParamHandle param) async { | ||
return CallApiResult(irisReturnCode: 0, data: {}); | ||
} | ||
} | ||
|
||
class _FakeNativeBindingDelegateProvider extends PlatformBindingsProvider { | ||
_FakeNativeBindingDelegateProvider(this.nativeBindingDelegate); | ||
|
||
final PlatformBindingsDelegateInterface nativeBindingDelegate; | ||
|
||
@override | ||
PlatformBindingsDelegateInterface provideNativeBindingDelegate() { | ||
return nativeBindingDelegate; | ||
} | ||
} | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
testWidgets( | ||
'IrisMethodChannel should call hot restart listener', | ||
(tester) async { | ||
await tester.pumpWidget(Container()); | ||
|
||
final irisMethodChannel = IrisMethodChannel( | ||
_FakeNativeBindingDelegateProvider(_FakeNativeBindingDelegate())); | ||
await irisMethodChannel.initilize([]); | ||
|
||
bool hotRestartListenerCalled = false; | ||
irisMethodChannel.addHotRestartListener((message) { | ||
hotRestartListenerCalled = true; | ||
}); | ||
|
||
(irisMethodChannel.getIrisMethodChannelInternal() | ||
as IrisMethodChannelInternalIO) | ||
.workerIsolate | ||
.kill(priority: Isolate.immediate); | ||
// Delayed 2 seconds to ensure `irisMethodChannel.workerIsolate.kill` done | ||
await Future.delayed(const Duration(seconds: 2)); | ||
|
||
expect(hotRestartListenerCalled, true); | ||
}, | ||
timeout: const Timeout(Duration(minutes: 10)), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export 'platform_cases_expect.dart' | ||
if (dart.library.io) 'platform_cases_actual_io.dart' | ||
if (dart.library.io) 'platform_cases_actual_io.dart' | ||
if (dart.library.html) 'platform_cases_actual_web.dart'; |