Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@harrylin98
Copy link
Contributor

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.

harrylhl and others added 8 commits December 16, 2025 20:41
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
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.92%. Comparing base (328b3ce) to head (1224f3e).
⚠️ Report is 1 commits behind head on unstable.

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     
Files with missing lines Coverage Δ
src/networking.c 88.34% <100.00%> (ø)
src/sds.c 88.71% <100.00%> (+0.34%) ⬆️
src/sds.h 82.66% <ø> (ø)
src/server.c 88.71% <100.00%> (-0.03%) ⬇️
src/server.h 100.00% <ø> (ø)

... and 23 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@harrylin98 harrylin98 marked this pull request as ready for review December 19, 2025 23:12
Copy link
Member

@JimB123 JimB123 left a 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

@madolson
Copy link
Member

madolson commented Dec 19, 2025

Reposting my top level comment:s

  • I don't think we should have two unit testing frameworks. I feel like we need to commit to incorporating the google testing framework. I'm not saying that is a blocker to start, but we should agree to move what we have.
  • We typically deep copy dependencies to make vending easier, maybe we don't care in this case because it is optional and not required? Not a particularly strong opinion.

Copy link
Member

@madolson madolson left a 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.

src/gtest/README.md Outdated Show resolved Hide resolved
}

// Verify mocking works via zfree
TEST_F(ExampleTest, TestMocking) {
Copy link
Member

@madolson madolson Dec 19, 2025

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

void free(void *ptr) __attribute__((deprecated));
)

Comment on lines +40 to +44
#include "ae.h"
#include "dict.h"
#include "server.h"
#include "adlist.h"
#include "zmalloc.h"
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 */
Copy link
Member

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?

Copy link
Contributor Author

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++.

Copy link
Member

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);
Copy link
Member

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
Copy link
Member

@madolson madolson Dec 19, 2025

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.

src/gtest/wrappers.h Show resolved Hide resolved
-include ../.make-settings
OPT=-O3 -DNDEBUG

ifeq ($(DEBUG_BUILD),1)
Copy link
Member

@madolson madolson Dec 19, 2025

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
Copy link
Member

@madolson madolson Dec 19, 2025

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.

Copy link
Member

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.

@madolson madolson added the run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) label Dec 20, 2025
.github/workflows/ci.yml Outdated Show resolved Hide resolved
Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
@madolson
Copy link
Member

@harrylhl Also check the 32 bit build, which seems to be failing now.

@zuiderkwast
Copy link
Contributor

  • We typically deep copy dependencies to make vending easier, maybe we don't care in this case because it is optional and not required? Not a particularly strong opinion.

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 apt install or similar.

@madolson
Copy link
Member

I prefer that we don't vendor it

That's a good point. It seems to available on hombrew and most most package managers. Let's do that!

harrylin98 and others added 2 commits December 21, 2025 23:17
Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
Signed-off-by: Harry Lin <49881386+harrylin98@users.noreply.github.com>
@harrylin98 harrylin98 force-pushed the unstable_gtest_PR branch 4 times, most recently from 7afc4cf to efbd4b9 Compare December 23, 2025 00:28
Signed-off-by: Harry Lin <harrylhl@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.