Skip to content

Commit

Permalink
Merge pull request #229 from Workiva/fix-2.19-mock-issue
Browse files Browse the repository at this point in the history
Avoid accessing private members of child modules
  • Loading branch information
rmconsole7-wk authored Sep 29, 2023
2 parents 9628be9 + 96665fb commit d5c469b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dart_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
sdk: [ 2.18.7 ]
sdk: [ 2.18.7 , 2.19.6]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/[email protected]
Expand Down
22 changes: 14 additions & 8 deletions lib/src/lifecycle_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ abstract class LifecycleModule extends SimpleModule with Disposable {
try {
manageDisposable(childModule);
_childModules.add(childModule);
childModule._parentContext = _loadContext;
childModule.parentContext = _loadContext;

await childModule.load();
try {
Expand All @@ -554,7 +554,7 @@ abstract class LifecycleModule extends SimpleModule with Disposable {
_didLoadChildModuleController.addError(error, stackTrace);
completer.completeError(error, stackTrace);
} finally {
childModule._parentContext = null;
childModule.parentContext = null;
}
}).catchError((Object error, StackTrace stackTrace) {
_logger.severe(
Expand All @@ -569,6 +569,12 @@ abstract class LifecycleModule extends SimpleModule with Disposable {
return completer.future;
}

/// Provide a way for a module to update its children's parentContext that is compatible with mocking in 2.19.
///
/// This is only intended for use within this file and is marked protected.
@protected
set parentContext(SpanContext? context) => _parentContext = context;

/// Public method to suspend the module.
///
/// Suspend indicates to the module that it should go into a low-activity
Expand Down Expand Up @@ -1034,9 +1040,9 @@ abstract class LifecycleModule extends SimpleModule with Disposable {
List<Future<Null>> childResumeFutures = <Future<Null>>[];
for (var child in _childModules.toList()) {
childResumeFutures.add(Future.sync(() {
child._parentContext = _activeSpan?.context;
child.parentContext = _activeSpan?.context;
return child.resume().whenComplete(() {
child._parentContext = null;
child.parentContext = null;
});
}));
}
Expand Down Expand Up @@ -1071,9 +1077,9 @@ abstract class LifecycleModule extends SimpleModule with Disposable {
List<Future<Null>> childSuspendFutures = <Future<Null>>[];
for (var child in _childModules.toList()) {
childSuspendFutures.add(Future.sync(() async {
child._parentContext = _activeSpan?.context;
child.parentContext = _activeSpan?.context;
return child.suspend().whenComplete(() {
child._parentContext = null;
child.parentContext = null;
});
}));
}
Expand Down Expand Up @@ -1119,9 +1125,9 @@ abstract class LifecycleModule extends SimpleModule with Disposable {

_willUnloadController.add(this);
await Future.wait(_childModules.toList().map((child) {
child._parentContext = _activeSpan?.context;
child.parentContext = _activeSpan?.context;
return child.unload().whenComplete(() {
child._parentContext = null;
child.parentContext = null;
});
}));
try {
Expand Down

0 comments on commit d5c469b

Please sign in to comment.