Skip to content

Comments

Unit test some worker protocol serializers#8923

Merged
thufschmitt merged 1 commit intoNixOS:masterfrom
obsidiansystems:test-proto
Sep 26, 2023
Merged

Unit test some worker protocol serializers#8923
thufschmitt merged 1 commit intoNixOS:masterfrom
obsidiansystems:test-proto

Conversation

@Ericson2314
Copy link
Member

Motivation

Context

Continue with the characterization testing idioms begun in c704844, but this time for unit tests.

Checklist for maintainers

Maintainers: tick if completed or explain if not relevant

  • agreed on idea
  • agreed on implementation strategy
  • tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • documentation in the manual
  • documentation in the internal API docs
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or incompatible change: updated release notes

Priorities

Add 👍 to pull requests you find important.

@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Sep 4, 2023
Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty nice :) I expect that test failures will be rather awful since we don't have a generic way to pretty-print the protocol, but at least we'll have some proper failures.

My main issue right now is with the documentation for these, which isn't really understandable without already knowing what's going on

You can run the whole testsuite with `make check`, or the tests for a specific component with `make libfoo-tests_RUN`.
Finer-grained filtering is also possible using the [--gtest_filter](https://google.github.io/googletest/advanced.html#running-a-subset-of-the-tests) command-line option, or the `GTEST_FILTER` environment variable.

### Characterization testing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gather this is the same as “Golden tests”, with the latter being (as far as I know) much more common. Maybe rename it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with that name before seen it was the one Wikipedia went with. See what I have since linked "below" too.


### Characterization testing

See below for a broder discussion.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was an existing long section on characterization testing, but within the functional tests. I am not sure what to put here, but I figured I shouldn't just repeat the same information. Certainly could be better! (e.g. maybe since this comes first most of the information should be moved here, and the other section should reference it.)

Comment on lines 13 to 68
### Characterization testing

See below for a broder discussion.
`_NIX_TEST_ACCEPT=1` is also used.
The data is in `unit-test-data`;
the path to that directory is passed to the unit test executable with the environment variable `UNIT_TEST_ENV`.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really have a clue as to what I should take out of this paragraph. What I'd expect to know is

  • How do I run these tests?
  • How do I edit one or add a new one?
  • How do I regenerate the golden files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 and 3 are now covered. (They are just unit tests, they are run like any other units tests). 2 I am not sure it is good to include yet because there is no general pattern yet.

I would like to convert a bunch of existing unit tests to use this sort of thing down the road, and at that point I think we'll have enough generalized infra to answer this question properly.

@thufschmitt
Copy link
Member

As a “would be good for later” item, how about keeping the old golden records forever and test that they still read properly? That would give us some extra guaranties on the backwards-compatibility of the protocol

@Ericson2314 Ericson2314 force-pushed the test-proto branch 2 times, most recently from 47571b9 to 645f184 Compare September 5, 2023 14:07
@Ericson2314
Copy link
Member Author

Ericson2314 commented Sep 5, 2023

OK, Added some more documentation. Some of the language is taken from #8886, but not the actual moving things around.

As a “would be good for later” item, how about keeping the old golden records forever and test that they still read properly? That would give us some extra guaranties on the backwards-compatibility of the protocol

Yeah the refactor of mine by adding the version info to {Read,Write}Conn allows us to do this very nicely!

Continue with the characterization testing idioms begun in
c704844, but this time for unit tests.

Co-authored-by: Andreas Rammhold <[email protected]>
Comment on lines +41 to +44
> **Note**
> Due to the way googletest works, downstream unit test executables will actually include and re-run upstream library tests.
> Therefore it is important that the same value for `_NIX_TEST_UNIT_DATA` be used with the tests for each library.
> That is why we have the test data nested within a single `unit-test-data` directory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to solve this by creating test support libraries, which don't include the actual tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we store them in hexdump -C format?
This will make changes easier to review.

00000000  40 00 00 00 00 00 00 00  74 65 78 74 3a 73 68 61  |@.......text:sha|
00000010  32 35 36 3a 31 76 62 32  78 64 36 37 37 35 30 6a  |256:1vb2xd67750j|
00000020  72 76 71 67 79 6b 78 72  66 35 69 70 6c 33 68 31  |rvqgykxrf5ipl3h1|
00000030  71 35 37 73 78 63 35 37  71 35 6e 7a 6a 77 35 36  |q57sxc57q5nzjw56|
00000040  62 71 70 33 73 78 7a 72  2b 00 00 00 00 00 00 00  |bqp3sxzr+.......|
00000050  66 69 78 65 64 3a 73 68  61 31 3a 31 61 6d 6b 36  |fixed:sha1:1amk6|
00000060  6e 37 77 78 6a 6c 77 34  71 6b 71 36 64 63 6a 36  |n7wxjlw4qkq6dcj6|
00000070  6d 6d 37 68 77 33 61 63  72 77 30 00 00 00 00 00  |mm7hw3acrw0.....|
00000080  43 00 00 00 00 00 00 00  66 69 78 65 64 3a 72 3a  |C.......fixed:r:|
00000090  73 68 61 32 35 36 3a 31  6c 72 31 38 37 76 36 64  |sha256:1lr187v6d|
000000a0  63 6b 31 72 6a 68 32 6a  36 73 76 70 69 6b 63 66  |ck1rjh2j6svpikcf|
000000b0  7a 35 33 77 79 6c 33 71  72 6c 63 62 62 34 30 35  |z53wyl3qrlcbb405|
000000c0  7a 6c 68 31 33 78 30 6b  68 68 68 00 00 00 00 00  |zlh13x0khhh.....|
000000d0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or this, which is more diff friendly

$ hexdump -e '8 1 "%02x "' -e '" | "' -e '8 "%_p"' -e '"\n"' unit-test-data/libstore/worker-protocol/content-address.bin 
40 00 00 00 00 00 00 00 | @.......
74 65 78 74 3a 73 68 61 | text:sha
32 35 36 3a 31 76 62 32 | 256:1vb2
78 64 36 37 37 35 30 6a | xd67750j
72 76 71 67 79 6b 78 72 | rvqgykxr
66 35 69 70 6c 33 68 31 | f5ipl3h1
71 35 37 73 78 63 35 37 | q57sxc57
71 35 6e 7a 6a 77 35 36 | q5nzjw56
62 71 70 33 73 78 7a 72 | bqp3sxzr
2b 00 00 00 00 00 00 00 | +.......
66 69 78 65 64 3a 73 68 | fixed:sh
61 31 3a 31 61 6d 6b 36 | a1:1amk6
6e 37 77 78 6a 6c 77 34 | n7wxjlw4
71 6b 71 36 64 63 6a 36 | qkq6dcj6
6d 6d 37 68 77 33 61 63 | mm7hw3ac
72 77 30 00 00 00 00 00 | rw0.....
43 00 00 00 00 00 00 00 | C.......
66 69 78 65 64 3a 72 3a | fixed:r:
73 68 61 32 35 36 3a 31 | sha256:1
6c 72 31 38 37 76 36 64 | lr187v6d
63 6b 31 72 6a 68 32 6a | ck1rjh2j
36 73 76 70 69 6b 63 66 | 6svpikcf
7a 35 33 77 79 6c 33 71 | z53wyl3q
72 6c 63 62 62 34 30 35 | rlcbb405
7a 6c 68 31 33 78 30 6b | zlh13x0k
68 68 68 00 00 00 00 00 | hhh.....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know how to "un-hexdump" files?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know how to "un-hexdump" files?

Do we need to? We can just diff the hex dumps, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have tests that read the dump and compare the result to something in the code; we want to test both the read and write directions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duh, of course 🤦‍♂️

xxd can do the reverse (at least it can reverse itself, dunno about the exact format spit out by hexdump). But I've no idea whether that's accessible as a library, and it's not available in the build env yet (though it's provided by busybox, so not a huge dependency).

So we can probably save that for a follow-up, unless someone wants to re-implement a hexdump in C++ (which probably isn't hard, but still)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I would prefer follow up. (Generally I hope these never change, rather we add new versions in new files, FWIW.)

Anything else before this can be merged?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, let's merge

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@thufschmitt thufschmitt merged commit c6faef6 into NixOS:master Sep 26, 2023
@Ericson2314 Ericson2314 deleted the test-proto branch September 26, 2023 15:13
tebowy pushed a commit to tebowy/nix that referenced this pull request Jul 11, 2024
Unit test some worker protocol serializers

(cherry picked from commit c6faef6)
Change-Id: I99e36f5f17eb7642211a4e42a16b143424f164b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants