Repository navigation
Add missing libgearman protocol tests - #524
Conversation
|
The values match the enum order in 1. Assert the sentinel too ASSERT_EQ(41, int(GEARMAN_COMMAND_GET_STATUS_UNIQUE));
ASSERT_EQ(42, int(GEARMAN_COMMAND_STATUS_RES_UNIQUE));
ASSERT_EQ(43, int(GEARMAN_COMMAND_MAX));Without this, someone can add a new command without adding a line here, which is how 41 and 42 went untested. With it, a new command makes the test fail until its assertion is added. 2. Cover the command table, not just the enum numbers The test checks the enum values but not the entries in for (int cmd= 0; cmd < int(GEARMAN_COMMAND_MAX); ++cmd)
{
ASSERT_EQ(cmd, int(gearman_command_info(gearman_command_t(cmd))->code));
}
ASSERT_EQ(1, gearman_command_info(GEARMAN_COMMAND_GET_STATUS_UNIQUE)->argc);
ASSERT_EQ(6, gearman_command_info(GEARMAN_COMMAND_STATUS_RES_UNIQUE)->argc);3. Out of scope, for a follow-up PR: 4. Possible alternative: these opcode numbers are part of the wire protocol and must never change. None of these should block merging. |
1781528 to
866f539
Compare
Verify that every entry in the command info table has the correct code (matching its enum index) and the expected argc value. This will catch altered rows that the previous enum-only assertions would have missed.
866f539 to
d660d23
Compare
|
Suggestion 1 sounded like a good idea to me, so I added that easily enough. Suggestion 2 was more difficult. It required the I'm going to skip suggestions 3 and 4 at this time. Feel free to submit PRs for these if you want them. |
There was a problem hiding this comment.
Thanks for taking on both suggestions. Moving the table check to internals.cc makes sense given the private header and the libgearmancore link. I checked all the argc values against gearmand_command_info_list[] and they match.
One small note, not blocking: gearman_command_info() already asserts code == command, so in a debug build a swapped row would abort t/internals instead of failing the assertion cleanly. The swap is still caught, so I'm fine leaving it as is.
I'll send a separate PR for the gearman_strcommand() / gearman_enum_strcommand() upper bound.
The gearman_strcommand() / gearman_enum_strcommand() bound is already fixed on master in #525.
Following up on #521 (comment), this pull request adds two missing protocol tests for
GEARMAN_COMMAND_GET_STATUS_UNIQUEandGEARMAN_COMMAND_STATUS_RES_UNIQUE.