Skip to content

Commit ab7d08c

Browse files
committed
Stricter retry verification.
1 parent 537363a commit ab7d08c

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

pkg/fake_gcloud/lib/retry_enforcer_storage.dart

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,41 @@
55
import 'dart:async';
66

77
import 'package:gcloud/storage.dart';
8+
import 'package:stack_trace/stack_trace.dart';
9+
10+
const _skippedFirstFrames = {
11+
'package:fake_gcloud/retry_enforcer_storage.dart',
12+
'package:pub_dev/shared/storage.dart',
13+
};
814

915
void _verifyRetryOnStack() {
1016
final st = StackTrace.current.toString();
11-
if (st.contains('package:retry/')) return;
12-
if (st.contains('retryAsync')) return; // lib/shared/utils.dart
17+
final trace = Trace.current();
18+
19+
// The first frame index outside of this file.
20+
var startFrameIndex = 0;
21+
while (_skippedFirstFrames.any((skipped) =>
22+
trace.frames[startFrameIndex].uri.toString().contains(skipped))) {
23+
startFrameIndex++;
24+
}
25+
26+
final firstRealFrame =
27+
trace.frames.skip(startFrameIndex).firstOrNull?.toString();
28+
if (firstRealFrame == null) {
29+
return;
30+
}
1331

1432
// detect direct test calls
15-
final linesWithoutThisFile = st
16-
.split('\n')
17-
.where((l) => !l.contains('retry_enforcer_storage.dart'))
18-
.toList();
19-
if (linesWithoutThisFile.isNotEmpty &&
20-
linesWithoutThisFile.first.contains('_test.dart')) {
33+
if (firstRealFrame.contains('_test.dart')) {
34+
return;
35+
}
36+
37+
// detect retry library
38+
if (firstRealFrame.contains('package:retry/')) {
39+
return;
40+
}
41+
// detect lib/shared/utils.dart use
42+
if (firstRealFrame.contains('retryAsync')) {
2143
return;
2244
}
2345

pkg/fake_gcloud/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies:
1212
gcloud: ^0.8.18
1313
logging: '>=0.11.3 <2.0.0'
1414
_discoveryapis_commons: ^1.0.7
15+
stack_trace: ^1.12.0
1516

1617
dev_dependencies:
1718
coverage: any # test already depends on it

0 commit comments

Comments
 (0)