Skip to content

Commit

Permalink
fixing some issues in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
escamoteur committed Nov 5, 2024
1 parent 5a9def2 commit 00579d9
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 53 deletions.
20 changes: 6 additions & 14 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ packages:
path: ".."
relative: true
source: path
version: "8.0.0-pre-1"
version: "8.0.2"
glob:
dependency: transitive
description:
Expand Down Expand Up @@ -193,18 +193,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.12.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -402,14 +402,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.3.0"
web_socket_channel:
dependency: transitive
description:
Expand All @@ -435,4 +427,4 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
dart: ">=3.3.0-0 <4.0.0"
7 changes: 6 additions & 1 deletion example/windows/flutter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
# https://github.com/flutter/flutter/issues/57146.
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")

# Set fallback configurations for older versions of the flutter tool.
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
set(FLUTTER_TARGET_PLATFORM "windows-x64")
endif()

# === Flutter Library ===
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")

Expand Down Expand Up @@ -92,7 +97,7 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
windows-x64 $<CONFIG>
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
VERBATIM
)
add_custom_target(flutter_assemble DEPENDS
Expand Down
5 changes: 5 additions & 0 deletions example/windows/runner/flutter_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ bool FlutterWindow::OnCreate() {
this->Show();
});

// Flutter can complete the first frame before the "show window" callback is
// registered. The following call ensures a frame is pending to ensure the
// window is shown. It is a no-op if the first frame hasn't completed yet.
flutter_controller_->ForceRedraw();

return true;
}

Expand Down
85 changes: 52 additions & 33 deletions test/async_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class TestClassParam {
class TestClass extends TestBaseClass {
GetIt? getIt;
bool initCompleted = false;
int initMsDelay;

/// if we do the initialisation from inside the constructor the init function has to signal GetIt
/// that it has finished. For that we need to pass in the completer that we got from the factory call
/// that we set up in the registration.
TestClass({required bool internalCompletion, this.getIt}) {
TestClass(
{required bool internalCompletion, this.initMsDelay = 10, this.getIt}) {
constructorCounter++;
if (internalCompletion) {
assert(getIt != null);
Expand All @@ -33,21 +35,21 @@ class TestClass extends TestBaseClass {

/// This one signals after a delay
Future initWithSignal() {
return Future.delayed(const Duration(milliseconds: 10)).then((_) {
return Future.delayed(Duration(milliseconds: initMsDelay)).then((_) {
getIt!.signalReady(this);
initCompleted = true;
});
}

// We use this as dummy init that will return a future
Future<TestClass> init() async {
await Future.delayed(const Duration(milliseconds: 10));
await Future.delayed(Duration(milliseconds: initMsDelay));
initCompleted = true;
return this;
}

Future<TestClass> initWithExeption() async {
await Future.delayed(const Duration(milliseconds: 10));
await Future.delayed(Duration(milliseconds: initMsDelay));
throw StateError('Intentional');
}

Expand All @@ -73,6 +75,7 @@ class TestClassWillSignalReady2 extends TestClass implements WillSignalReady {
class TestClass2 extends TestClass {
TestClass2({
required super.internalCompletion,
super.initMsDelay = 10,
super.getIt,
});
}
Expand Down Expand Up @@ -346,29 +349,45 @@ void main() {
});

test('ready automatic signalling for async Singletons', () async {
final getIt = GetIt.instance;
getIt.reset();
try {
final getIt = GetIt.instance;
await getIt.reset();

getIt.registerSingletonAsync<TestClass>(
() async => TestClass(internalCompletion: false).init(),
);
getIt.registerSingletonAsync<TestClass2>(
() async {
final instance = TestClass2(internalCompletion: false);
await instance.init();
return instance;
},
);
getIt.registerSingletonAsync(
() async => TestClass2(internalCompletion: false)..init(),
instanceName: 'Second Instance',
);
expect(getIt.allReady(), completes);
getIt.registerSingletonAsync<TestClass>(
() async => TestClass(internalCompletion: false).init(),
);
getIt.registerSingletonAsync<TestClass2>(
() async {
final instance =
TestClass2(internalCompletion: false, initMsDelay: 50);
await instance.init();
return instance;
},
);
getIt.registerSingletonAsync<TestClass>(
() async => TestClass2(internalCompletion: false).init(),
instanceName: 'Second Instance',
);

expect(getIt.isReadySync<TestClass>(), false);
expect(getIt.isReadySync<TestClass2>(), false);
expect(
getIt.isReadySync<TestClass>(instanceName: 'Second Instance'), false);

await getIt.allReady();

expect(getIt.isReadySync<TestClass>(), true);
expect(getIt.isReadySync<TestClass2>(), true);
expect(
getIt.isReadySync<TestClass>(instanceName: 'Second Instance'), true);
} on Exception catch (e) {
print(e);
}
});

test('isReady propagates Error', () async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();

getIt.registerSingletonAsync<TestClass>(
() async => TestClass(internalCompletion: false).initWithExeption(),
Expand All @@ -379,7 +398,7 @@ void main() {
test('allReady propagades Exceptions that occur in the factory functions',
() async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();

getIt.registerSingletonAsync<TestClass>(
() async => TestClass(internalCompletion: false).init(),
Expand All @@ -400,7 +419,7 @@ void main() {
});
test('ready manual synchronisation of sequence', () async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();
errorCounter = 0;
var flag1 = false;
var flag2 = false;
Expand Down Expand Up @@ -659,7 +678,7 @@ void main() {

test('asyncFactory called with getAsync', () async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();

getIt.registerFactoryAsync<TestClass>(
() => Future.value(TestClass(internalCompletion: false)),
Expand Down Expand Up @@ -754,9 +773,9 @@ void main() {
expect(instance2.param2, null);
});

test('register factory with Params with wrong type', () {
test('register factory with Params with wrong type', () async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();

constructorCounter = 0;
getIt.registerFactoryParamAsync<TestClassParam, String, int>(
Expand All @@ -770,9 +789,9 @@ void main() {
});

test('register factory with Params with non-nullable type but not pass it',
() {
() async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();

constructorCounter = 0;
getIt.registerFactoryParamAsync<TestClassParam, String, void>(
Expand All @@ -787,7 +806,7 @@ void main() {

test('asyncFactory called with get instead of getAsync', () async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();

getIt.registerFactoryAsync<TestClass>(
() => Future.value(TestClass(internalCompletion: false)),
Expand All @@ -801,7 +820,7 @@ void main() {

test('asyncLazySingleton called with get before it was ready', () async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();

getIt.registerLazySingletonAsync<TestClass>(
() => Future.value(TestClass(internalCompletion: false)),
Expand All @@ -816,7 +835,7 @@ void main() {

test('asyncLazySingleton called with getAsync', () async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();

getIt.registerLazySingletonAsync<TestClass>(
() => Future.value(TestClass(internalCompletion: false)..init()),
Expand All @@ -843,7 +862,7 @@ void main() {

test('isReady called on asyncLazySingleton ', () async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();

getIt.registerLazySingletonAsync<TestClass>(
() => Future.value(TestClass(internalCompletion: false)),
Expand Down
10 changes: 5 additions & 5 deletions test/skip_double_registration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void main() {
final getIt = GetIt.instance;
getIt.allowReassignment = false;
getIt.skipDoubleRegistration = false;
getIt.reset();
await getIt.reset();
getIt.registerSingleton<DataStore>(MockDataStore());

expect(
Expand All @@ -17,7 +17,7 @@ void main() {

test(' replaces dependency safely ', () async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();
getIt.allowReassignment = true;
getIt.skipDoubleRegistration = false;
getIt.registerSingleton<DataStore>(MockDataStore());
Expand All @@ -28,7 +28,7 @@ void main() {

test(' Ignores Double registration error ', () async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();
getIt.allowReassignment = false;
getIt.skipDoubleRegistration = true;
getIt.registerSingleton<DataStore>(MockDataStore());
Expand All @@ -41,7 +41,7 @@ void main() {
test(' Ignores Double named registration error ', () async {
final getIt = GetIt.instance;
const instanceName = 'named';
getIt.reset();
await getIt.reset();
getIt.allowReassignment = false;
getIt.skipDoubleRegistration = true;
getIt.registerSingleton<DataStore>(RemoteDataStore());
Expand All @@ -61,7 +61,7 @@ void main() {

test(' does not care about [skipDoubleRegistration] varibale ', () async {
final getIt = GetIt.instance;
getIt.reset();
await getIt.reset();
getIt.allowReassignment = true;
getIt.skipDoubleRegistration = true;
getIt.registerSingleton<DataStore>(MockDataStore());
Expand Down

0 comments on commit 00579d9

Please sign in to comment.