Skip to content

Commit 00579d9

Browse files
committed
fixing some issues in tests
1 parent 5a9def2 commit 00579d9

File tree

5 files changed

+74
-53
lines changed

5 files changed

+74
-53
lines changed

example/pubspec.lock

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ packages:
124124
path: ".."
125125
relative: true
126126
source: path
127-
version: "8.0.0-pre-1"
127+
version: "8.0.2"
128128
glob:
129129
dependency: transitive
130130
description:
@@ -193,18 +193,18 @@ packages:
193193
dependency: transitive
194194
description:
195195
name: material_color_utilities
196-
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
196+
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
197197
url: "https://pub.dev"
198198
source: hosted
199-
version: "0.5.0"
199+
version: "0.8.0"
200200
meta:
201201
dependency: transitive
202202
description:
203203
name: meta
204-
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
204+
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
205205
url: "https://pub.dev"
206206
source: hosted
207-
version: "1.10.0"
207+
version: "1.12.0"
208208
mime:
209209
dependency: transitive
210210
description:
@@ -402,14 +402,6 @@ packages:
402402
url: "https://pub.dev"
403403
source: hosted
404404
version: "1.1.0"
405-
web:
406-
dependency: transitive
407-
description:
408-
name: web
409-
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
410-
url: "https://pub.dev"
411-
source: hosted
412-
version: "0.3.0"
413405
web_socket_channel:
414406
dependency: transitive
415407
description:
@@ -435,4 +427,4 @@ packages:
435427
source: hosted
436428
version: "3.1.2"
437429
sdks:
438-
dart: ">=3.2.0-194.0.dev <4.0.0"
430+
dart: ">=3.3.0-0 <4.0.0"

example/windows/flutter/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
1010
# https://github.com/flutter/flutter/issues/57146.
1111
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
1212

13+
# Set fallback configurations for older versions of the flutter tool.
14+
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
15+
set(FLUTTER_TARGET_PLATFORM "windows-x64")
16+
endif()
17+
1318
# === Flutter Library ===
1419
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
1520

@@ -92,7 +97,7 @@ add_custom_command(
9297
COMMAND ${CMAKE_COMMAND} -E env
9398
${FLUTTER_TOOL_ENVIRONMENT}
9499
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
95-
windows-x64 $<CONFIG>
100+
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
96101
VERBATIM
97102
)
98103
add_custom_target(flutter_assemble DEPENDS

example/windows/runner/flutter_window.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ bool FlutterWindow::OnCreate() {
3131
this->Show();
3232
});
3333

34+
// Flutter can complete the first frame before the "show window" callback is
35+
// registered. The following call ensures a frame is pending to ensure the
36+
// window is shown. It is a no-op if the first frame hasn't completed yet.
37+
flutter_controller_->ForceRedraw();
38+
3439
return true;
3540
}
3641

test/async_test.dart

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ class TestClassParam {
1919
class TestClass extends TestBaseClass {
2020
GetIt? getIt;
2121
bool initCompleted = false;
22+
int initMsDelay;
2223

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

3436
/// This one signals after a delay
3537
Future initWithSignal() {
36-
return Future.delayed(const Duration(milliseconds: 10)).then((_) {
38+
return Future.delayed(Duration(milliseconds: initMsDelay)).then((_) {
3739
getIt!.signalReady(this);
3840
initCompleted = true;
3941
});
4042
}
4143

4244
// We use this as dummy init that will return a future
4345
Future<TestClass> init() async {
44-
await Future.delayed(const Duration(milliseconds: 10));
46+
await Future.delayed(Duration(milliseconds: initMsDelay));
4547
initCompleted = true;
4648
return this;
4749
}
4850

4951
Future<TestClass> initWithExeption() async {
50-
await Future.delayed(const Duration(milliseconds: 10));
52+
await Future.delayed(Duration(milliseconds: initMsDelay));
5153
throw StateError('Intentional');
5254
}
5355

@@ -73,6 +75,7 @@ class TestClassWillSignalReady2 extends TestClass implements WillSignalReady {
7375
class TestClass2 extends TestClass {
7476
TestClass2({
7577
required super.internalCompletion,
78+
super.initMsDelay = 10,
7679
super.getIt,
7780
});
7881
}
@@ -346,29 +349,45 @@ void main() {
346349
});
347350

348351
test('ready automatic signalling for async Singletons', () async {
349-
final getIt = GetIt.instance;
350-
getIt.reset();
352+
try {
353+
final getIt = GetIt.instance;
354+
await getIt.reset();
351355

352-
getIt.registerSingletonAsync<TestClass>(
353-
() async => TestClass(internalCompletion: false).init(),
354-
);
355-
getIt.registerSingletonAsync<TestClass2>(
356-
() async {
357-
final instance = TestClass2(internalCompletion: false);
358-
await instance.init();
359-
return instance;
360-
},
361-
);
362-
getIt.registerSingletonAsync(
363-
() async => TestClass2(internalCompletion: false)..init(),
364-
instanceName: 'Second Instance',
365-
);
366-
expect(getIt.allReady(), completes);
356+
getIt.registerSingletonAsync<TestClass>(
357+
() async => TestClass(internalCompletion: false).init(),
358+
);
359+
getIt.registerSingletonAsync<TestClass2>(
360+
() async {
361+
final instance =
362+
TestClass2(internalCompletion: false, initMsDelay: 50);
363+
await instance.init();
364+
return instance;
365+
},
366+
);
367+
getIt.registerSingletonAsync<TestClass>(
368+
() async => TestClass2(internalCompletion: false).init(),
369+
instanceName: 'Second Instance',
370+
);
371+
372+
expect(getIt.isReadySync<TestClass>(), false);
373+
expect(getIt.isReadySync<TestClass2>(), false);
374+
expect(
375+
getIt.isReadySync<TestClass>(instanceName: 'Second Instance'), false);
376+
377+
await getIt.allReady();
378+
379+
expect(getIt.isReadySync<TestClass>(), true);
380+
expect(getIt.isReadySync<TestClass2>(), true);
381+
expect(
382+
getIt.isReadySync<TestClass>(instanceName: 'Second Instance'), true);
383+
} on Exception catch (e) {
384+
print(e);
385+
}
367386
});
368387

369388
test('isReady propagates Error', () async {
370389
final getIt = GetIt.instance;
371-
getIt.reset();
390+
await getIt.reset();
372391

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

384403
getIt.registerSingletonAsync<TestClass>(
385404
() async => TestClass(internalCompletion: false).init(),
@@ -400,7 +419,7 @@ void main() {
400419
});
401420
test('ready manual synchronisation of sequence', () async {
402421
final getIt = GetIt.instance;
403-
getIt.reset();
422+
await getIt.reset();
404423
errorCounter = 0;
405424
var flag1 = false;
406425
var flag2 = false;
@@ -659,7 +678,7 @@ void main() {
659678

660679
test('asyncFactory called with getAsync', () async {
661680
final getIt = GetIt.instance;
662-
getIt.reset();
681+
await getIt.reset();
663682

664683
getIt.registerFactoryAsync<TestClass>(
665684
() => Future.value(TestClass(internalCompletion: false)),
@@ -754,9 +773,9 @@ void main() {
754773
expect(instance2.param2, null);
755774
});
756775

757-
test('register factory with Params with wrong type', () {
776+
test('register factory with Params with wrong type', () async {
758777
final getIt = GetIt.instance;
759-
getIt.reset();
778+
await getIt.reset();
760779

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

772791
test('register factory with Params with non-nullable type but not pass it',
773-
() {
792+
() async {
774793
final getIt = GetIt.instance;
775-
getIt.reset();
794+
await getIt.reset();
776795

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

788807
test('asyncFactory called with get instead of getAsync', () async {
789808
final getIt = GetIt.instance;
790-
getIt.reset();
809+
await getIt.reset();
791810

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

802821
test('asyncLazySingleton called with get before it was ready', () async {
803822
final getIt = GetIt.instance;
804-
getIt.reset();
823+
await getIt.reset();
805824

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

817836
test('asyncLazySingleton called with getAsync', () async {
818837
final getIt = GetIt.instance;
819-
getIt.reset();
838+
await getIt.reset();
820839

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

844863
test('isReady called on asyncLazySingleton ', () async {
845864
final getIt = GetIt.instance;
846-
getIt.reset();
865+
await getIt.reset();
847866

848867
getIt.registerLazySingletonAsync<TestClass>(
849868
() => Future.value(TestClass(internalCompletion: false)),

test/skip_double_registration_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ void main() {
66
final getIt = GetIt.instance;
77
getIt.allowReassignment = false;
88
getIt.skipDoubleRegistration = false;
9-
getIt.reset();
9+
await getIt.reset();
1010
getIt.registerSingleton<DataStore>(MockDataStore());
1111

1212
expect(
@@ -17,7 +17,7 @@ void main() {
1717

1818
test(' replaces dependency safely ', () async {
1919
final getIt = GetIt.instance;
20-
getIt.reset();
20+
await getIt.reset();
2121
getIt.allowReassignment = true;
2222
getIt.skipDoubleRegistration = false;
2323
getIt.registerSingleton<DataStore>(MockDataStore());
@@ -28,7 +28,7 @@ void main() {
2828

2929
test(' Ignores Double registration error ', () async {
3030
final getIt = GetIt.instance;
31-
getIt.reset();
31+
await getIt.reset();
3232
getIt.allowReassignment = false;
3333
getIt.skipDoubleRegistration = true;
3434
getIt.registerSingleton<DataStore>(MockDataStore());
@@ -41,7 +41,7 @@ void main() {
4141
test(' Ignores Double named registration error ', () async {
4242
final getIt = GetIt.instance;
4343
const instanceName = 'named';
44-
getIt.reset();
44+
await getIt.reset();
4545
getIt.allowReassignment = false;
4646
getIt.skipDoubleRegistration = true;
4747
getIt.registerSingleton<DataStore>(RemoteDataStore());
@@ -61,7 +61,7 @@ void main() {
6161

6262
test(' does not care about [skipDoubleRegistration] varibale ', () async {
6363
final getIt = GetIt.instance;
64-
getIt.reset();
64+
await getIt.reset();
6565
getIt.allowReassignment = true;
6666
getIt.skipDoubleRegistration = true;
6767
getIt.registerSingleton<DataStore>(MockDataStore());

0 commit comments

Comments
 (0)