-
Notifications
You must be signed in to change notification settings - Fork 972
Introduce GoogleTest framework for Valkey unit testing #2956
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
base: unstable
Are you sure you want to change the base?
Conversation
Signed-off-by: Harry Lin <harrylhl@amazon.com>
Signed-off-by: Harry Lin <harrylhl@amazon.com>
Co-authored-by: Jim Brunner <brunnerj@amazon.com> Signed-off-by: Harry Lin <harrylhl@amazon.com>
Co-authored-by: Jim Brunner <brunnerj@amazon.com> Signed-off-by: Harry Lin <harrylhl@amazon.com>
Signed-off-by: Harry Lin <harrylhl@amazon.com>
Signed-off-by: Harry Lin <harrylhl@amazon.com>
Signed-off-by: Harry Lin <harrylhl@amazon.com>
Signed-off-by: Harry Lin <harrylhl@amazon.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #2956 +/- ##
============================================
+ Coverage 73.69% 73.92% +0.23%
============================================
Files 125 125
Lines 69138 69345 +207
============================================
+ Hits 50949 51266 +317
+ Misses 18189 18079 -110
🚀 New features to boost your workflow:
|
JimB123
left a comment
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.
I like the documentation and the integration with the current unit tests. We can see the example tests already running as the test builds are executed. Nice work pulling this all together and ensuring support across all of the platforms.
This provides the capability for much richer unit testing.
I look forward to using this during the development of the forkless capabilities: #2878
|
Reposting my top level comment:s
|
madolson
left a comment
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.
I think there is a bit more cleanup to do in make files, but I think they're close as of right now.
Left some other comments.
| } | ||
|
|
||
| // Verify mocking works via zfree | ||
| TEST_F(ExampleTest, TestMocking) { |
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.
I think this is the type of mocking that got ElastiCache into trouble. This is trying to make sure zfree is called, but there are better systemic ways like deprecating not using free (See
Line 4077 in 0a9cb98
| void free(void *ptr) __attribute__((deprecated)); |
| #include "ae.h" | ||
| #include "dict.h" | ||
| #include "server.h" | ||
| #include "adlist.h" | ||
| #include "zmalloc.h" |
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.
Do we need server.h here? I feel like a bunch of these are not useful.
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.
server.h pulls in core headers and ensures consistent C/C++ compatibility, so I’d suggest keeping it included.
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.
The main Valkey project doesn't guarantee C/C++ compatibility, it's a C project. I don't want to enforce that as a constraint.
|
|
||
| #ifndef __WRAPPERS_H | ||
| #define __WRAPPERS_H | ||
| #define _Atomic /* nothing */ |
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.
What does the nothing comment mean?
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.
It means _Atomic is being defined as an empty macro.
This strips the _Atomic keyword so the code can compile as C++ (where _Atomic is not a valid keyword). This is a compatibility trick when sharing headers between C and C++.
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.
Can you document that instead of a "trick".
| * See: https://github.com/google/googletest/blob/master/googlemock/docs/gmock_faq.md#can-i-mock-a-variadic-function | ||
| * Example: serverLog(int level, const char *fmt, ...) should NOT be mocked. | ||
| */ | ||
| long long __wrap_aeCreateTimeEvent(aeEventLoop *eventLoop, long long milliseconds, aeTimeProc *proc, void *clientData, aeEventFinalizerProc *finalizerProc); |
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.
I would like to just keep this one, and remove the other wraps. I don't think you should be mocking creation of basic objects. I think you want to be mocking things you don't get deterministic results from (like timers, network, disk etc.
| @echo '$(TEST_CFLAGS)' | cmp -s - $@ || echo '$(TEST_CFLAGS)' > $@ | ||
|
|
||
| # OSS Valkey library dependencies | ||
| VALKEY_LIB := ../libvalkey.a |
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.
The Valkey client is called libvalkey. We build this as valkey.a in the top level directory. I don't know if we need to rebuild it here, and if we do, let's call it something else.
| -include ../.make-settings | ||
| OPT=-O3 -DNDEBUG | ||
|
|
||
| ifeq ($(DEBUG_BUILD),1) |
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.
What is this DEBUG_BUILD option? EDIT: I think this might be an AWS thing.
| #include "dict.h" | ||
| } | ||
|
|
||
| // Use a class name descriptive of your test unit |
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.
I think it is required to end with TEST no? Would be useful to document any other requirements since this is the example.
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.
We should add a style checker for CPP tests.
Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
|
@harrylhl Also check the 32 bit build, which seems to be failing now. |
I prefer that we don't vendor it, since it's optional and only for developers, not useful for end users. I think we should handle it like we handle the optional OpenSSL, i.e. the user has to install it locally using |
That's a good point. It seems to available on hombrew and most most package managers. Let's do that! |
Co-authored-by: Madelyn Olson <madelyneolson@gmail.com> Signed-off-by: Harry Lin <49881386+harrylin98@users.noreply.github.com>
7afc4cf to
efbd4b9
Compare
Signed-off-by: Harry Lin <harrylhl@amazon.com>
efbd4b9 to
1224f3e
Compare
This PR adds GoogleTest (gtest) support to Valkey to enable writing modern unit tests.
Motivation:
GoogleTest provides richer assertions, test fixtures, mocking support, and improved diagnostics, helping improve test coverage and maintainability over time.
Summary:
The change is limited to test infrastructure, and existing C unit tests remain unchanged.
This PR focuses only on integrating the framework and includes a small set of example tests to demonstrate usage.
For more details, see
src/gtest/README.md.