Skip to content

Commit 16347a8

Browse files
authored
fix: track was not ended when behaviour resulted in a future
1 parent b8dcad0 commit 16347a8

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.1
2+
3+
* fix: track was not ended when behaviour resulted in a future
4+
15
## 3.0.0
26

37
* feat!: upgraded to dart v3

lib/src/behaviour_mixin.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ mixin BehaviourMixin {
5555
BehaviourTrack? track,
5656
) async {
5757
try {
58-
return await future;
58+
final result = await future;
59+
track?.end();
60+
return result;
5961
} catch (error, stackTrace) {
6062
return _catch(error, stackTrace, track);
6163
}

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: behaviour
22
description:
33
This package adds support for behaviours. Behaviours are classes of which the
44
instances are used as functions.
5-
version: 3.0.0
5+
version: 3.0.1
66
repository: https://github.com/wim07101993/behaviour
77

88
environment:

test/src/behaviour_mixin_test.dart

+16-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void main() {
8989
});
9090
});
9191

92-
test('should start and end the track', () async {
92+
test('should start and end the track in case of sync', () async {
9393
// act
9494
await behaviour.executeAction((track) => const Success(Object()));
9595

@@ -102,6 +102,21 @@ void main() {
102102
verifyNever(() => mockTrack.stopWithException(any(), any()));
103103
});
104104

105+
test('should start and end the track in case of future', () async {
106+
// act
107+
await behaviour.executeAction(
108+
(track) => Future.value(const Success(Object())),
109+
);
110+
111+
// assert
112+
verifyInOrder([
113+
() => mockTrack.start(),
114+
() => mockTrack.end(),
115+
]);
116+
verifyNever(() => mockTrack.stopWithError(any(), any()));
117+
verifyNever(() => mockTrack.stopWithException(any(), any()));
118+
});
119+
105120
test('should execute and return result of action', () async {
106121
// arrange
107122
final expected = faker.randomGenerator.element<ExceptionOr<String>>([

0 commit comments

Comments
 (0)