He-Pin opened a new issue, #3222:
URL: https://github.com/apache/pekko/issues/3222
### Motivation
`BehaviorTestKit` trait 提供了 `run`、`runAsk`、`signal`、`retrieveEffect`
等方法用于同步测试 typed actor 行为,但缺少 `stop()`/`shutdown()`/`close()` 方法。用户无法在测试结束后正确清理
actor 资源。
### 当前代码行为
`BehaviorTestKit.scala` trait 定义:
```scala
// BehaviorTestKit.scala
trait BehaviorTestKit[T] {
def run(cmd: T): BehaviorTestKit[T]
def runAsk(...): ...
def signal(signal: Signal): Unit
def retrieveEffect(): Effect
...
// 无 stop()/shutdown()/close()
}
```
用户发送 `PostStop` signal 来模拟停止,但这不等于实际停止 actor 和清理内部状态。
### 预期行为
提供 `stop()` 或 `close()` 方法:
1. 发送 `PostStop` signal 给 behavior
2. 清理内部状态(如 stash buffer、子 actor 引用)
3. 标记 TestKit 为已关闭,后续调用报错
### 代码证据
-
`actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/scaladsl/BehaviorTestKit.scala`
— trait 定义,无 stop 方法
### 复现方式
使用 `BehaviorTestKit` 测试需要清理资源的 actor(如持有 TimerScheduler、子 actor 的
actor),测试结束后无法正确清理。
### 影响范围
- 模块:`pekko-actor-testkit-typed`
- 影响所有使用 BehaviorTestKit 的单元测试
- 测试间可能存在状态泄漏(timer、子 actor 引用未释放)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]