记一次 patch 提交
感谢 Angus Salkeld 春风化雨般的教导,此次 patch 让我更加认知测试的重要性。
近期稍闲,于是在 Heat 项目找了个名为 Cannot delete the stack after replacing image during stack-update Edit 的 bug 来 fix。本文并不是介绍如何 fix bug,而是感谢社区大神们春风化雨的教导和赞美社区互助的品质。首先介绍该 bug,其描述如下:
Steps to Reproduce:
* create a stack with with a single server (see attached example template)
* update the stack and replace the image the instance is using
- This will fail with the error "Conflict: Port <uuid> is still in
use. (HTTP 409) "
* Try to delete the stack
- This will fail with the error "Failed to DELETE :
Error deleting backup resources:
Resource DELETE failed:
Forbidden: You are not authorized to perform the requested action,
dentity:delete_user. (HTTP 403)"
折腾不久找出原因,简单的说就是 stack.stack_user_project_id 参数未被赋值,于是简单暴力的直接赋值,由于对 mox/mock 掌握不深,故没有编写单元测试,第一个 patch 共 5 行代码,review 结果可想而知。
从上图可知:
- Jason Dunsmore 要求 patch 必须有测试用例
- Steve Baker 细心的教我如何编写测试用例
- Angus Salkeld 考虑更为全面,于是他把 patch 邮件给我,如下图。
粗心的我直接提交 Angus Salkeld 给的 patch,踩了他特意埋的坑后(主要在注释),羞愧的难以自容,立刻学习 mox/mock 的用法。
之后根据 Angus Salkeld 的建议再次提交 patch,他又鼓励我添加一个用例,覆盖另一种场景。
nearly there, i had the focus of testing on the delete, but it seems it is
on the update-replacement of the server. Let's make that more explicit in
the functional test, otherwise it's going to be confusing what this test is
really doing.
Angus Salkeld 是 Heat 的 PTL,他愿如此不愿其烦的教导一个小菜鸟,令我感触颇深。