-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Prevent multiple initializations of internal resources when `Rtc…
…Engine.initialize` is called simultaneously (#1712) A case like: ```dart for (int i = 0; i < 5; ++i) { rtcEngine.initialize(RtcEngineContext( appId: engineAppId, areaCode: AreaCode.areaCodeGlob.value(), logConfig: LogConfig(filePath: logPath), )); } ``` This causes `irisMethodChannel.initilize(args)`, and `_initializeInternal(context)` called multiple times, which causes unexpected behaviors. `iris_method_channel` fix: AgoraIO-Extensions/iris_method_channel_flutter#98
- Loading branch information
1 parent
02aec26
commit 462cfc3
Showing
6 changed files
with
208 additions
and
20 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
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
2 changes: 2 additions & 0 deletions
2
test_shard/integration_test_app/integration_test/fake_apis_call_integration_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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import 'package:integration_test/integration_test.dart'; | ||
|
||
import 'testcases/mediarecorder_fake_test_testcases.dart' as fake_mediarecorder; | ||
import 'testcases/rtcengine_fake_test_testcases.dart' as fake_rtcengine; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
fake_mediarecorder.testCases(); | ||
fake_rtcengine.testCases(); | ||
} |
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
145 changes: 145 additions & 0 deletions
145
..._shard/integration_test_app/integration_test/testcases/rtcengine_fake_test_testcases.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,145 @@ | ||
import 'package:agora_rtc_engine/agora_rtc_engine.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import 'package:agora_rtc_engine/src/impl/platform/io/native_iris_api_engine_binding_delegate.dart'; | ||
import '../fake/fake_iris_method_channel.dart'; | ||
import 'package:agora_rtc_engine/src/impl/agora_rtc_engine_impl.dart'; | ||
import 'package:path_provider/path_provider.dart'; | ||
import 'package:path/path.dart' as path; | ||
import 'dart:io'; | ||
|
||
void testCases() { | ||
group('RtcEngine.initialize', () { | ||
final FakeIrisMethodChannel irisMethodChannel = | ||
FakeIrisMethodChannel(IrisApiEngineNativeBindingDelegateProvider()); | ||
final RtcEngine rtcEngine = | ||
RtcEngineImpl.createForTesting(irisMethodChannel: irisMethodChannel); | ||
|
||
setUp(() { | ||
irisMethodChannel.reset(); | ||
}); | ||
|
||
testWidgets( | ||
'only initialize once', | ||
(WidgetTester tester) async { | ||
String engineAppId = const String.fromEnvironment('TEST_APP_ID', | ||
defaultValue: '<YOUR_APP_ID>'); | ||
|
||
Directory appDocDir = await getApplicationDocumentsDirectory(); | ||
String logPath = path.join(appDocDir.path, 'test_log.txt'); | ||
|
||
await rtcEngine.initialize(RtcEngineContext( | ||
appId: engineAppId, | ||
areaCode: AreaCode.areaCodeGlob.value(), | ||
logConfig: LogConfig(filePath: logPath), | ||
)); | ||
await rtcEngine.initialize(RtcEngineContext( | ||
appId: engineAppId, | ||
areaCode: AreaCode.areaCodeGlob.value(), | ||
logConfig: LogConfig(filePath: logPath), | ||
)); | ||
await rtcEngine.initialize(RtcEngineContext( | ||
appId: engineAppId, | ||
areaCode: AreaCode.areaCodeGlob.value(), | ||
logConfig: LogConfig(filePath: logPath), | ||
)); | ||
final calls = irisMethodChannel.methodCallQueue | ||
.where((e) => e.funcName == 'initilize') | ||
.toList(); | ||
expect(calls.length == 1, true); | ||
|
||
await rtcEngine.release(); | ||
}, | ||
); | ||
|
||
testWidgets( | ||
'only initialize once when called simultaneously', | ||
(WidgetTester tester) async { | ||
String engineAppId = const String.fromEnvironment('TEST_APP_ID', | ||
defaultValue: '<YOUR_APP_ID>'); | ||
|
||
Directory appDocDir = await getApplicationDocumentsDirectory(); | ||
String logPath = path.join(appDocDir.path, 'test_log.txt'); | ||
|
||
for (int i = 0; i < 5; ++i) { | ||
rtcEngine.initialize(RtcEngineContext( | ||
appId: engineAppId, | ||
areaCode: AreaCode.areaCodeGlob.value(), | ||
logConfig: LogConfig(filePath: logPath), | ||
)); | ||
} | ||
// Wait for the 5 times calls of `irisMethodChannel.initilize` are completed. | ||
await Future.delayed(const Duration(milliseconds: 1000)); | ||
|
||
final calls = irisMethodChannel.methodCallQueue | ||
.where((e) => e.funcName == 'initilize') | ||
.toList(); | ||
expect(calls.length == 1, true); | ||
|
||
await rtcEngine.release(); | ||
}, | ||
); | ||
|
||
testWidgets( | ||
're-initialize once after release', | ||
(WidgetTester tester) async { | ||
String engineAppId = const String.fromEnvironment('TEST_APP_ID', | ||
defaultValue: '<YOUR_APP_ID>'); | ||
|
||
Directory appDocDir = await getApplicationDocumentsDirectory(); | ||
String logPath = path.join(appDocDir.path, 'test_log.txt'); | ||
{ | ||
await rtcEngine.initialize(RtcEngineContext( | ||
appId: engineAppId, | ||
areaCode: AreaCode.areaCodeGlob.value(), | ||
logConfig: LogConfig(filePath: logPath), | ||
)); | ||
await rtcEngine.initialize(RtcEngineContext( | ||
appId: engineAppId, | ||
areaCode: AreaCode.areaCodeGlob.value(), | ||
logConfig: LogConfig(filePath: logPath), | ||
)); | ||
await rtcEngine.initialize(RtcEngineContext( | ||
appId: engineAppId, | ||
areaCode: AreaCode.areaCodeGlob.value(), | ||
logConfig: LogConfig(filePath: logPath), | ||
)); | ||
|
||
final calls = irisMethodChannel.methodCallQueue | ||
.where((e) => e.funcName == 'initilize') | ||
.toList(); | ||
expect(calls.length == 1, true); | ||
|
||
await rtcEngine.release(); | ||
} | ||
|
||
irisMethodChannel.reset(); | ||
|
||
{ | ||
await rtcEngine.initialize(RtcEngineContext( | ||
appId: engineAppId, | ||
areaCode: AreaCode.areaCodeGlob.value(), | ||
logConfig: LogConfig(filePath: logPath), | ||
)); | ||
await rtcEngine.initialize(RtcEngineContext( | ||
appId: engineAppId, | ||
areaCode: AreaCode.areaCodeGlob.value(), | ||
logConfig: LogConfig(filePath: logPath), | ||
)); | ||
await rtcEngine.initialize(RtcEngineContext( | ||
appId: engineAppId, | ||
areaCode: AreaCode.areaCodeGlob.value(), | ||
logConfig: LogConfig(filePath: logPath), | ||
)); | ||
|
||
final calls = irisMethodChannel.methodCallQueue | ||
.where((e) => e.funcName == 'initilize') | ||
.toList(); | ||
expect(calls.length == 1, true); | ||
} | ||
|
||
await rtcEngine.release(); | ||
}, | ||
); | ||
}); | ||
} |