Repository navigation
fix(system): 修复队列完成后电源操作因先请求前端关闭而永远无法执行的问题 #612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import unittest | ||
| from unittest.mock import AsyncMock, patch | ||
|
|
||
| from app.services.system import System | ||
|
|
||
|
|
||
| class SetPowerExecutionTest(unittest.IsolatedAsyncioTestCase): | ||
| async def test_system_power_action_executes_without_frontend_close(self): | ||
| # 前端退出会连带结束后端进程,系统电源动作不得依赖前端关闭(issue #611) | ||
| with ( | ||
| patch.object( | ||
| System, "_request_frontend_close", new_callable=AsyncMock | ||
| ) as request_frontend_close, | ||
| patch( | ||
| "app.services.system.power.execute", new_callable=AsyncMock | ||
| ) as execute, | ||
| ): | ||
| await System.set_power("ShutdownForce") | ||
|
|
||
| execute.assert_awaited_once_with("ShutdownForce") | ||
| request_frontend_close.assert_not_awaited() | ||
|
|
||
| async def test_kill_self_still_requests_frontend_close(self): | ||
| # KillSelf 是后端自行退出,保留先请求前端退出的既有行为 | ||
| server = type("Server", (), {"should_exit": False})() | ||
| with ( | ||
| patch.object( | ||
| System, "_request_frontend_close", new_callable=AsyncMock | ||
| ) as request_frontend_close, | ||
| patch("app.core.config.Config.server", server), | ||
| ): | ||
| await System.set_power("KillSelf") | ||
|
|
||
| request_frontend_close.assert_awaited_once() | ||
| self.assertTrue(server.should_exit) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (testing): 回归测试在未模拟
kill_emulator_processes的情况下调用System.set_power("ShutdownForce"),因此会扫描主机进程表,并终止名称包含模拟器相关关键词的所有进程。在存在匹配的模拟器进程的机器上运行该测试,可能会终止该进程,使测试具有破坏性或不稳定性。触发条件: 当测试在开发者机器或 CI 机器上运行,且其中存在名称包含
Nemu、emulator或MuMu的进程时。建议修复: 在调用
set_power之前,在测试中使用AsyncMock对System.kill_emulator_processes进行 patch。Original comment in English
issue (testing): The regression test calls
System.set_power("ShutdownForce")without mockingkill_emulator_processes, so it scans the host process table and kills every process whose name contains emulator-related keywords. Running the test on a machine with a matching emulator process can terminate that process and make the test destructive or flaky.Triggers: When the test runs on a developer or CI machine with a process whose name contains
Nemu,emulator, orMuMu.Suggested fix: Patch
System.kill_emulator_processeswith anAsyncMockin the test before invokingset_power.