Integration tests + improved thread safety #15
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds integration testing against example projects in both kotlin and java. Included is a test that attempts to send 1000 requests at the same time to the example backend (not all 1000 actually get sent at once due to the concurrency limitation on the OkHttpClient) in order to test the concurrency and thread safety of the package.
This test highlighted an issue with the old
withKonigKontext
function in the kotlin implementation. Since gRPC Context utilizes ThreadLocal, mutliple Kotlin coroutines can run on the same thread and potentially have access to the wrong gRPC Context. The grpc-kotlin package ran into this issue as well, and implemented a custom CoroutineContext element specifically for ensuring that a given coroutine only can access its proper corresponding gRPC Context. I have utilized the same class to ensure thatwithKonigKontext
is concurrency safe. Also, since grpc-kotlin has already solved this issue, any kotlin coroutine server implementations that register theKonigKontextInterceptor
will also be concurrency safe. With these changes, all kotlin implementations should be concurrency safe.All Java implementations were already concurrency safe since concurrent threads in Java are each their own thread and thus cannot have access to an incorrect gRPC Context.
Grpc-kotlin also has example projects inside the same repo as the library itself, so I'm going to use that as an example to try and see if I can get those projects moved into this repo. That way any breaking changes will require updating the examples and integration tests can be run on PRs