Skip to content

Commit

Permalink
fix: Add tests and Changelog text
Browse files Browse the repository at this point in the history
  • Loading branch information
c-lucera-pvotal committed Aug 20, 2024
1 parent 8f08c49 commit ab73121
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.0.1

* Fix header and trailing not completing if the call is terminated. Fixes [#727](https://github.com/grpc/grpc-dart/issues/727)

## 4.0.0

* Set compressed flag correctly for grpc-encoding = identity. Fixes [#669](https://github.com/grpc/grpc-dart/issues/669) (https://github.com/grpc/grpc-dart/pull/693)
Expand Down
4 changes: 2 additions & 2 deletions lib/src/client/call.dart
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,11 @@ class ClientCall<Q, R> implements Response {
}
if (!_headers.isCompleted) {
_headers.completeError(
GrpcError.unimplemented("Request terminated before headers"));
GrpcError.unimplemented('Request terminated before headers'));
}
if (!_trailers.isCompleted) {
_trailers.completeError(
GrpcError.unimplemented("Request terminated before trailers"));
GrpcError.unimplemented('Request terminated before trailers'));
}
await Future.wait(futures);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: grpc
description: Dart implementation of gRPC, a high performance, open-source universal RPC framework.
version: 4.0.0
version: 4.0.1

repository: https://github.com/grpc/grpc-dart

Expand Down
67 changes: 67 additions & 0 deletions test/client_tests/call_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,26 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:grpc/grpc.dart';
import 'package:grpc/src/client/call.dart';
import 'package:test/test.dart';

import '../src/client_utils.dart';

void main() {
const dummyValue = 0;
const cancelDurationMillis = 300;

late ClientHarness harness;

setUp(() {
harness = ClientHarness()..setUp();
});

tearDown(() {
harness.tearDown();
});

test('WebCallOptions mergeWith CallOptions returns WebCallOptions', () {
final options =
WebCallOptions(bypassCorsPreflight: true, withCredentials: true);
Expand All @@ -28,4 +44,55 @@ void main() {
expect(mergedOptions.bypassCorsPreflight, true);
expect(mergedOptions.withCredentials, true);
});

test(
'Terminating a call correctly complete headers and trailers futures',
() async {
final clientCall = harness.client.unary(dummyValue);
clientCall.catchError((error) {
expect(error.codeName, equals('CANCELLED'));
return dummyValue;
});

Future.delayed(
Duration(milliseconds: cancelDurationMillis),
).then((_) {
clientCall.cancel();
});

await expectLater(
clientCall.headers,
throwsA(
isA<GrpcError>()
.having(
(e) => e.codeName,
'Test codename',
contains('UNIMPLEMENTED'),
)
.having(
(e) => e.message,
'Test message',
contains('headers'),
),
),
);
await expectLater(
clientCall.trailers,
throwsA(
isA<GrpcError>()
.having(
(e) => e.codeName,
'Test codename',
contains('UNIMPLEMENTED'),
)
.having(
(e) => e.message,
'Test message',
contains('trailers'),
),
),
);
},
timeout: Timeout(Duration(milliseconds: cancelDurationMillis * 2)),
);
}

0 comments on commit ab73121

Please sign in to comment.