Skip to content

Commit

Permalink
Issue #49: Test for forwarding socket exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1u committed Oct 20, 2021
1 parent 8a61893 commit b005637
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions test/error_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,35 @@ import 'package:redis/redis.dart';
import 'package:test/test.dart';

import 'main.dart';
import 'dart:io';

Future<Command> generate_connect_broken() {
return RedisConnection().connect("localhost", 2);
}

main() {
group("Throw received Redis Errors", () {
test("Expect error when sending Garbage", () async {
Command cmd = await generate_connect();

expect(cmd.send_object("GARBAGE"), throwsA(isRedisError));
expect(() => cmd.send_object("GARBAGE"), throwsA(isRedisError));
});
});

group("Recover after received Redis Errors", () {
test("Expect error when sending Garbage 2", () async {
Command cmd = await generate_connect();
expect(cmd.send_object(["GARBAGE"]), throwsA(isRedisError));
expect(() => cmd.send_object(["GARBAGE"]), throwsA(isRedisError));
// next two commands over same connection should be fine
expect(await cmd.send_object(["SET","garbage_test","grb"]),equals("OK"));
expect(await cmd.send_object(["GET","garbage_test"]),equals("grb"));
var ok = await cmd.send_object(["SET", "garbage_test", "grb"]);
expect(ok, equals("OK"));
var v = await cmd.send_object(["GET", "garbage_test"]);
expect(v, equals("grb"));
});
});

group("Handle low lewel error", () {
test("handle error that is out of our contoll", () {
expect(generate_connect_broken, throwsA(isA<SocketException>()));
});
});
}
Expand Down

0 comments on commit b005637

Please sign in to comment.