dapr / dapr/java-sdk

Remove Maven dependency to run apps in ITs and stop process leaks.

オープン
#201 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
area/test/integration-tests kind/enhancement P2 size/M triaged/resolved
主要言語
Java
スター
300
フォーク
230
平均マージ
5日 1時間
マージ済み PR(30日)
5

説明

Integration tests invoke `dapr run` with a `mvn` command. Instead, change how services are invoked for ITs.

### 1. Use `daprd` instead of `dapr`
Follow instructions in [debugging with daprd in IntelliJ](https://github.com/dapr/docs/tree/master/howto/intellij-debugging-daprd) to understand how `daprd` can be invoked directly. Change [DaprRun.java](https://github.com/dapr/java-sdk/blob/master/sdk-tests/src/test/java/io/dapr/it/DaprRun.java) to invoke daprd in a separate process.

### 2. Run test app as a new thread in same JVM as tests
Now, instead of running the service application as a process by invoking `mvn`, run the main function directly as a new thread inside the same JVM as tests. This will avoid having to build a separate fatjar only for test apps. There are environment variables expected by the test app, and those cannot be changed at runtime. On the other hand, all environment variables defined in [Properties.java](https://github.com/dapr/java-sdk/blob/master/sdk/src/main/java/io/dapr/utils/Properties.java) can be overridden via System properties. Since System Properties are global, see this [work around](https://stackoverflow.com/questions/9579958/system-setproperty-used-by-a-thread-impacts-other-thread-in-communication-to-ext) on how to have System Properties in ThreadLocal (not ideal for production but OK for tests IMO).

### 3. Make test app optional in `DaprRun.java`
Some tests do not need a test app, they just need `daprd`. So, offer a new constructor in `DaprRun.java` that does not have a test app class. Remove [EmptyService.java](https://github.com/dapr/java-sdk/blob/master/sdk-tests/src/test/java/io/dapr/it/services/EmptyService.java) and use the new constructor for all previous uses of that class.

### 4. Stopping `daprd`
Make sure that `DaprRun.java` stops `daprd` in `stop()` method - try gracefully for 1 minute and then forcefully. Because we are not using `dapr` anymore, `dapr stop` will not work anymore. Stop the process from JVM directly.

### 5. Verify process leaks.
* Run ITs once and use Sysinternals' `pskill.exe` as `pskill daprd.exe` and validate no process was killed. For unix systems, use `ps auxwww | grep daprd` and validate there is no `daprd` process in the output, only the `grep` process. Feel free to use another solution to validate this if preferred.
* Artificially make one of the ITs fail an assertion and run ITs. Replay validation for no `daprd` process leaked.
* Artificially throw an exception in the `@Before` method of an IT and run ITs. Replay validation for no `daprd` process leaked.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

sdk-tests/src/test/java/io/dapr/it/DaprRun.java から始め、IT サービスがどのように起動・設定されるかについて sdk/src/main/java/io/dapr/utils/Properties.java を確認してください。sdk-tests/src/test/java/io/dapr/it/services/EmptyService.java のすべての使用箇所を確認し、その後統合テストを実行して、正常終了、アサーション失敗、@Before の例外が発生した場合にも daprd が停止し、プロセスが残らないことを検証してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
testing
issue の種類
リファクタリング
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。