Skip to content

Commit

Permalink
[server] Fix server considering ClientExceptions as successes
Browse files Browse the repository at this point in the history
Miscategorized ClientExceptions as successes. Moved the success return statement to prevent such cases in the future. Added a test dedicated to the ClientException failure mode (test existed for 500s).
  • Loading branch information
AsturaPhoenix committed Aug 4, 2023
1 parent 00db561 commit bb146ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion server/lib/aquamarine_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ class AquamarineServer {
final uv = await ofsClient.fetchUv(simulationTime);
await persistence.writeUv(simulationTime, latlngHash!, uv);
}
return FetchResult.success;
} on ResourceException catch (e) {
log.warning(e.message);

Expand All @@ -312,8 +313,8 @@ class AquamarineServer {
}
} on http.ClientException catch (e, s) {
log.warning('Failed to fetch $simulationTime', e, s);
return FetchResult.transientFailure;
}
return FetchResult.success;
});

switch (result) {
Expand Down
27 changes: 26 additions & 1 deletion server/test/aquamarine_server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:aquamarine_server_interface/io.dart';
import 'package:aquamarine_server_interface/types.dart';
import 'package:clock/clock.dart';
import 'package:file/memory.dart';
import 'package:http/http.dart' as http;
import 'package:latlng/latlng.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
Expand Down Expand Up @@ -397,7 +398,7 @@ void main() {
);

test(
'continues trying in the case of transient failures',
'continues trying in the case of transient failures with status codes',
() => withClock(clock, () async {
final ofsClient = MockOfsClient();
final persistence = MockPersistence();
Expand All @@ -419,6 +420,30 @@ void main() {
}),
);

test(
'continues trying in the case of transient failures with client '
'exceptions',
() => withClock(clock, () async {
final ofsClient = MockOfsClient();
final persistence = MockPersistence();

final t = simulationTime.timestamp;

final server = AquamarineServer(
ofsClient: ofsClient,
persistence: persistence,
);

when(ofsClient.fetchLatLngUv(any))
.thenAnswer((_) async => throw http.ClientException('foo'));

expect(
await server.fetchSimulationRun(t), FetchResult.transientFailure);

verify(ofsClient.fetchLatLngUv(any)).called(6 + 1 + 48);
}),
);

test(
'skips up-to-date hours',
() => withClock(clock, () async {
Expand Down

0 comments on commit bb146ff

Please sign in to comment.