Skip to content

Commit 19edaa7

Browse files
committed
Refactor + merge post-test verification.
1 parent 537363a commit 19edaa7

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

app/test/shared/test_services.dart

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -121,30 +121,35 @@ class FakeAppengineEnv {
121121
await fork(() async {
122122
await fn();
123123
});
124-
final problems =
125-
await IntegrityChecker(dbService).findProblems().toList();
126-
if (problems.isNotEmpty &&
127-
(integrityProblem == null ||
128-
integrityProblem.matchAsPrefix(problems.first) == null)) {
129-
throw Exception(
130-
'${problems.length} integrity problems detected. First: ${problems.first}');
131-
} else if (problems.isEmpty && integrityProblem != null) {
132-
throw Exception('Integrity problem expected but not present.');
133-
}
134-
135-
// TODO: run all background tasks here
136-
await backfillNewFields();
137-
138-
// re-run integrity checks on the updated state
139-
final laterProblems =
140-
await IntegrityChecker(dbService).findProblems().toList();
141-
expect(laterProblems, problems);
124+
await _postTestVerification(integrityProblem: integrityProblem);
142125
},
143126
);
144127
}) as R;
145128
}
146129
}
147130

131+
Future<void> _postTestVerification({
132+
required Pattern? integrityProblem,
133+
}) async {
134+
final problems = await IntegrityChecker(dbService).findProblems().toList();
135+
if (problems.isNotEmpty &&
136+
(integrityProblem == null ||
137+
integrityProblem.matchAsPrefix(problems.first) == null)) {
138+
throw Exception(
139+
'${problems.length} integrity problems detected. First: ${problems.first}');
140+
} else if (problems.isEmpty && integrityProblem != null) {
141+
throw Exception('Integrity problem expected but not present.');
142+
}
143+
144+
// TODO: run all background tasks here
145+
await backfillNewFields();
146+
147+
// re-run integrity checks on the updated state
148+
final laterProblems =
149+
await IntegrityChecker(dbService).findProblems().toList();
150+
expect(laterProblems, problems);
151+
}
152+
148153
/// Registers test with [name] and runs it in pkg/fake_gcloud's scope, populated
149154
/// with [testProfile] data.
150155
@isTest
@@ -210,17 +215,7 @@ void testWithFakeTime(
210215
await fork(() async {
211216
await fn(fakeTime);
212217
});
213-
// post-test integrity check
214-
final problems =
215-
await IntegrityChecker(dbService).findProblems().toList();
216-
if (problems.isNotEmpty &&
217-
(integrityProblem == null ||
218-
integrityProblem.matchAsPrefix(problems.first) == null)) {
219-
throw Exception(
220-
'${problems.length} integrity problems detected. First: ${problems.first}');
221-
} else if (problems.isEmpty && integrityProblem != null) {
222-
throw Exception('Integrity problem expected but not present.');
223-
}
218+
await _postTestVerification(integrityProblem: integrityProblem);
224219
},
225220
);
226221
});

0 commit comments

Comments
 (0)