Skip to content

Introduce GoogleTest for Valkey unit testing#3241

Merged
madolson merged 10 commits intovalkey-io:unstablefrom
harrylin98:Feb20_final_merge
Feb 26, 2026
Merged

Introduce GoogleTest for Valkey unit testing#3241
madolson merged 10 commits intovalkey-io:unstablefrom
harrylin98:Feb20_final_merge

Conversation

@harrylin98
Copy link
Contributor

@harrylin98 harrylin98 commented Feb 21, 2026

This is the final merge PR that merged feature-gtest into unstable.

This PR adds GoogleTest (gtest) support to Valkey to enable
writing modern unit tests,as mentioned in #2878

Motivation:
GoogleTest provides richer assertions, test fixtures, mocking
support, and improved diagnostics, helping improve test coverage
and maintainability over time.

For more details, see src/gtest/README.md.

Changes

This PR integrates the GoogleTest framework and migrates all
existing C unit tests to GoogleTest.

Authors
Harry Lin, Alina Liu

harrylin98 and others added 7 commits January 14, 2026 12:28
### 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`.

---------

Signed-off-by: Harry Lin <harrylhl@amazon.com>
Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
Signed-off-by: Harry Lin <49881386+harrylin98@users.noreply.github.com>
Co-authored-by: Harry Lin <harrylhl@amazon.com>
Co-authored-by: Jim Brunner <brunnerj@amazon.com>
Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
Co-authored-by: Jacob Murphy <jkmurphy@google.com>
This PR fixes the issue where changes to src files did not trigger a
rebuild of
libvalkey.a when rerunning `make test-gtest`.

It also resolves the problem where unchanged .cpp test files were
unnecessarily recompiled
during make test-gtest.

Now:

If nothing changed:
- Nothing rebuilds, no relinking occurs.

If only C++ test files changed:
- Both libvalkey.a and C++ test files recompile (because release.o
changes)
- Test executable relinks

If only src code changed:
- Only libvalkey.a rebuilds
- C++ test files do not recompile
- Test executable relinks

If both changed:
- Both libvalkey.a and C++ test files rebuild
- Test executable relinks

Signed-off-by: Harry Lin <harrylhl@amazon.com>
Co-authored-by: Harry Lin <harrylhl@amazon.com>
Resolved conflicts by merging both gtest and libbacktrace features:
- ci.yml: Combined gtest dependencies with libbacktrace support
- Makefile: Added libbacktrace configuration alongside gtest-parallel
- daily.yml: Merged g++-multilib with libbacktrace build steps

All build configurations now support both USE_LIBBACKTRACE and gtest unit tests.
## Overview:

This PR converted existing C unit tests to GTEST based on this
introduction of GoogleTest framework valkey-io#2956 , as mentioned in valkey-io#2878 .

## Details:
1. Kept the previous test logic as much as possible, also kept all
original comments from C unit tests.
2. Deleted C unit tests.
3. Changed headers: include "generated_wrappers.hpp" and remove all
header files already in "generated_wrappers.hpp".
4. Used extern "C" to wrap the C include files to prevent name mangling.
5. Added Test Fixture with Setup/Teardown.

## Notes:
1. `ustime` is included in `util.h`, so deleted some duplicated
`ustime`.
2. A lot of C tests include `.c` files directly to use static functions,
but we don't want to copy static functions from `.c` to `.cpp`, so I
added wrapper functions (prefix: `testOnly`) to `.c` to use in `.cpp`
file.
3. Some C tests have shared state which is incompatible with
gtest-parallel, so I changed them to isolated tests. (e.g. in
`test_dict.cpp`, I made `_dict` an instance variable created fresh in
SetUp() for each test, and added back the necessary setup code to each
test so they can run independently in any order or in parallel).


## Testing:
* GTEST: 253 tests + 32 disabled tests (285 tests in total) all pass

---------

Signed-off-by: Alina Liu <liusalisa6363@gmail.com>
Signed-off-by: Harry Lin <harrylhl@amazon.com>
Signed-off-by: Harry Lin <49881386+harrylin98@users.noreply.github.com>
Signed-off-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com>
Co-authored-by: Harry Lin <harrylhl@amazon.com>
Co-authored-by: Harry Lin <49881386+harrylin98@users.noreply.github.com>
Co-authored-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com>
Signed-off-by: Harry Lin <harrylhl@amazon.com>
Signed-off-by: Harry Lin <49881386+harrylin98@users.noreply.github.com>
Signed-off-by: Alina Liu <liusalisa6363@gmail.com>
Signed-off-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com>
Co-authored-by: Harry Lin <harrylhl@amazon.com>
Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
Co-authored-by: Alina Liu <liusalisa6363@gmail.com>
Co-authored-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com>
Signed-off-by: Harry Lin <harrylhl@amazon.com>
@harrylin98 harrylin98 closed this Feb 21, 2026
@harrylin98 harrylin98 reopened this Feb 21, 2026
@harrylin98 harrylin98 changed the title Merge feature gtest into unstable. Introduce GoogleTest framework for Valkey unit testing Feb 21, 2026
@harrylin98 harrylin98 changed the title Introduce GoogleTest framework for Valkey unit testing Introduce GoogleTest for Valkey unit testing Feb 21, 2026
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.

Incremental merge of the various other gtest improvements. @valkey-io/core-team please take a look.

@madolson madolson added the major-decision-pending Major decision pending by TSC team label Feb 23, 2026
@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (39332bd) to head (e2906b2).
⚠️ Report is 4 commits behind head on unstable.

Additional details and impacted files
@@       Coverage Diff        @@
##   unstable   #3241   +/-   ##
================================
================================
🚀 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.

Signed-off-by: harrylin98 <harrylin980107@gmail.com>
Signed-off-by: harrylin98 <harrylin980107@gmail.com>
Signed-off-by: harrylin98 <harrylin980107@gmail.com>
Copy link
Contributor

@sarthakaggarwal97 sarthakaggarwal97 left a comment

Choose a reason for hiding this comment

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

Thanks for the change! @harrylin98 would you please fix DCO as well!

@harrylin98
Copy link
Contributor Author

Thanks for the change! @harrylin98 would you please fix DCO as well!

This commit was already merged in the feature-gtest branch, there was no DCO issues and the commit was fully verified during the merge time.

f766e99

@madolson madolson added major-decision-approved Major decision approved by TSC team and removed major-decision-pending Major decision pending by TSC team labels Feb 26, 2026
@madolson madolson merged commit f3e957c into valkey-io:unstable Feb 26, 2026
92 checks passed
hpatro pushed a commit to hpatro/valkey that referenced this pull request Mar 5, 2026
This PR adds GoogleTest (gtest) support to Valkey to enable
writing modern unit tests,as mentioned in
valkey-io#2878

**Motivation**:
GoogleTest provides richer assertions, test fixtures, mocking
support, and improved diagnostics, helping improve test coverage
and maintainability over time.

For more details, see `src/gtest/README.md`.

**Changes**

This PR integrates the GoogleTest framework and migrates all
existing C unit tests to GoogleTest.

---------

Signed-off-by: Harry Lin <harrylhl@amazon.com>
Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
Signed-off-by: Alina Liu <liusalisa6363@gmail.com>
Signed-off-by: Jacob Murphy <jkmurphy@google.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Co-authored-by: Harry Lin <harrylhl@amazon.com>
Co-authored-by: Jim Brunner <brunnerj@amazon.com>
Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
Co-authored-by: Jacob Murphy <jkmurphy@google.com>
Co-authored-by: Alina Liu <liusalisa6363@gmail.com>
Signed-off-by: Harkrishn Patro <bunty.hari@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

major-decision-approved Major decision approved by TSC team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants