Skip to content
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

ci: Parallelize change detector #1871

Merged
merged 24 commits into from
Sep 19, 2023

Conversation

nasdf
Copy link
Member

@nasdf nasdf commented Sep 12, 2023

Relevant issue(s)

Resolves #1436

Description

This PR allows the change detector to run in parallel with other tests.

There are also a few other improvements to the change detector:

  • change detector logic is moved to a new tests/change_detector package
    • change detector specific logic in tests/integration is now more obvious
  • change detector now operates on distinct source and target branches
    • this enables you to test branches outside of the currently checked out branch
  • change detector manages its own environment variables.
    • running go test ./tests/change_detector/... will work without env variables
  • change detector temp directories are now all cleaned up after running

Todo before merging:

  • update default branch and repository
  • document change detector data format changes

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

make test:changes

Specify the platform(s) on which this was tested:

  • MacOS

@nasdf nasdf added the area/testing Related to any test or testing suite label Sep 12, 2023
@nasdf nasdf added this to the DefraDB v0.8 milestone Sep 12, 2023
@nasdf nasdf self-assigned this Sep 12, 2023
@codecov
Copy link

codecov bot commented Sep 12, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.01% ⚠️

Comparison is base (2020a1e) 70.31% compared to head (cf6267f) 70.30%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1871      +/-   ##
===========================================
- Coverage    70.31%   70.30%   -0.01%     
===========================================
  Files          232      232              
  Lines        24192    24192              
===========================================
- Hits         17010    17007       -3     
- Misses        6021     6023       +2     
- Partials      1161     1162       +1     
Flag Coverage Δ
all-tests 70.30% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2020a1e...cf6267f. Read the comment docs.

@nasdf nasdf mentioned this pull request Sep 12, 2023
8 tasks
"github.com/stretchr/testify/require"
)

func TestChanges(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: I really like this approach, it is simpler and neater than some kind of file lock IMO.

// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package change_detector
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion(non-blocking, minor): Whilst I like the approach, I do dislike that this test will be executed by default with go test ./..., I think it might be nicer if we exclude this test by default, perhaps using a build flag. This would however complicate the github action matrix stuff.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added build tag here and updated Makefile to include --tags change_detector.

Makefile Outdated
@@ -294,8 +295,7 @@ test\:coverage-html:

.PHONY: test\:changes
test\:changes:
@$(MAKE) deps:lens
env DEFRA_DETECT_DATABASE_CHANGES=true DEFRA_CLIENT_GO=true gotestsum -- ./... -shuffle=on -p 1
gotestsum --format testname -- ./$(CHANGE_DETECTOR_TEST_DIRECTORY)/... -shuffle=on
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: It does look like -shuffle=on adds no value here? Or is it passed down into the child tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed shuffle flag.

@@ -202,7 +155,7 @@ func init() {
//
// Usage: AssertPanicAndSkipChangeDetection(t, func() { executeTestCase(t, test) })
func AssertPanicAndSkipChangeDetection(t *testing.T, f assert.PanicTestFunc) bool {
if IsDetectingDbChanges() {
if change_detector.Enabled {
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: Perhaps a non-snake case package name or import alias name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to changeDetector with an alias.

Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

I do really like these changes, specially the clean isolation of change detection test under the test/ folder and ability to specify source and target in a clean manner.

@nasdf
Copy link
Member Author

nasdf commented Sep 18, 2023

I do really like these changes, specially the clean isolation of change detection test under the test/ folder and ability to specify source and target in a clean manner.

I've updated it to default to the local repo if target is not defined. This should make it simpler to run in CI.


var targetRepoDir string
if targetBranch == "" {
// default to the local branch
Copy link
Contributor

@AndrewSisley AndrewSisley Sep 18, 2023

Choose a reason for hiding this comment

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

question: This seems odd and a bit dangerous no? If I understand correctly this will now default to testing against itself, which is essentially the same as running go test ./...?

This does seem like an easy way to accidentally not run the change detector at all.

EDIT: I misunderstood, we now have source and target branches, and the new source branch is what the old target used to be. Ignore this comment :)

…ream defradb repo. update checkIfDatabaseFormatChangesAreDocumented to use source and target directories
@nasdf nasdf marked this pull request as ready for review September 18, 2023 21:01
@nasdf nasdf requested a review from a team September 18, 2023 21:02
Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

Question: were you able to introduce breaking changes locally and test that the change detector actually catches the breaking change?

@nasdf
Copy link
Member Author

nasdf commented Sep 18, 2023

Question: were you able to introduce breaking changes locally and test that the change detector actually catches the breaking change?

No, but I can do that and report back.

Update: I was able to get it to fail, but it's also failing on this test case which should be passing.

--- FAIL: TestMutationUpdateOneToMany_InvalidAliasRelationNameToLinkFromManySide_Collection (0.02s)
        	            	panic: runtime error: index out of range [0] with length 0 [recovered]
        	            		panic: runtime error: index out of range [0] with length 0
        	            	
        	            	goroutine 1926 [running]:
        	            	testing.tRunner.func1.2({0x1059a91c0, 0x14000518048})
        	            		/usr/local/go/src/testing/testing.go:1526 +0x1c8
        	            	testing.tRunner.func1()
        	            		/usr/local/go/src/testing/testing.go:1529 +0x384
        	            	panic({0x1059a91c0, 0x14000518048})
        	            		/usr/local/go/src/runtime/panic.go:884 +0x204
        	            	github.com/sourcenetwork/defradb/tests/integration.updateDocViaColSave(0x140008352d8?, {{0x0, 0x0}, 0x0, 0x0, {0x14000041a40, 0x3d}, {0x105395e96, 0x2c}, 0x0}, ...)
        	            		/Users/keenan/Projects/defradb/tests/integration/utils2.go:1204 +0x110
        	            	github.com/sourcenetwork/defradb/tests/integration.updateDoc.func1()
        	            		/Users/keenan/Projects/defradb/tests/integration/utils2.go:1190 +0x80
        	            	github.com/sourcenetwork/defradb/tests/integration.withRetry({0x14000010068, 0x1, 0x140008353b8?}, 0x0, 0x14000835440)
        	            		/Users/keenan/Projects/defradb/tests/integration/utils2.go:1403 +0x90
        	            	github.com/sourcenetwork/defradb/tests/integration.updateDoc(0x14000a37a00, {{0x0, 0x0}, 0x0, 0x0, {0x14000041a40, 0x3d}, {0x105395e96, 0x2c}, 0x0})
        	            		/Users/keenan/Projects/defradb/tests/integration/utils2.go:1187 +0x2e0
        	            	github.com/sourcenetwork/defradb/tests/integration.executeTestCase({0x105aa7670?, 0x14000196018}, 0x14000a37860, {0x140004ba080, 0x2, 0x2}, {{0x1053b3d45, 0x44}, {0x1400052d680, 0x4, ...}, ...}, ...)
        	            		/Users/keenan/Projects/defradb/tests/integration/utils2.go:385 +0xf40
        	            	github.com/sourcenetwork/defradb/tests/integration.ExecuteTestCase(0x140004cfd50?, {{0x1053b3d45, 0x44}, {0x1400052d680, 0x4, 0x4}, {0x1, {0x140004ba060, 0x2, 0x2}}})
        	            		/Users/keenan/Projects/defradb/tests/integration/utils2.go:311 +0x504
        	            	github.com/sourcenetwork/defradb/tests/integration/mutation/update/field_kinds/one_to_many.executeTestCase(...)
        	            		/Users/keenan/Projects/defradb/tests/integration/mutation/update/field_kinds/one_to_many/utils.go:20
        	            	github.com/sourcenetwork/defradb/tests/integration/mutation/update/field_kinds/one_to_many.TestMutationUpdateOneToMany_InvalidAliasRelationNameToLinkFromManySide_Collection(0x1400015f230?)
        	            		/Users/keenan/Projects/defradb/tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go:255 +0x458
        	            	testing.tRunner(0x14000a37860, 0x105a8c758)
        	            		/usr/local/go/src/testing/testing.go:1576 +0x10c
        	            	created by testing.(*T).Run
        	            		/usr/local/go/src/testing/testing.go:1629 +0x368
        	            	FAIL	github.com/sourcenetwork/defradb/tests/integration/mutation/update/field_kinds/one_to_many	1.769s
        	            	FAIL

@nasdf
Copy link
Member Author

nasdf commented Sep 19, 2023

Question: were you able to introduce breaking changes locally and test that the change detector actually catches the breaking change?

No, but I can do that and report back.

Update: I was able to get it to fail, but it's also failing on this test case which should be passing.

--- FAIL: TestMutationUpdateOneToMany_InvalidAliasRelationNameToLinkFromManySide_Collection (0.02s)
        	            	panic: runtime error: index out of range [0] with length 0 [recovered]
        	            		panic: runtime error: index out of range [0] with length 0
        	            	
        	            	goroutine 1926 [running]:
        	            	testing.tRunner.func1.2({0x1059a91c0, 0x14000518048})
        	            		/usr/local/go/src/testing/testing.go:1526 +0x1c8
        	            	testing.tRunner.func1()
        	            		/usr/local/go/src/testing/testing.go:1529 +0x384
        	            	panic({0x1059a91c0, 0x14000518048})
        	            		/usr/local/go/src/runtime/panic.go:884 +0x204
        	            	github.com/sourcenetwork/defradb/tests/integration.updateDocViaColSave(0x140008352d8?, {{0x0, 0x0}, 0x0, 0x0, {0x14000041a40, 0x3d}, {0x105395e96, 0x2c}, 0x0}, ...)
        	            		/Users/keenan/Projects/defradb/tests/integration/utils2.go:1204 +0x110
        	            	github.com/sourcenetwork/defradb/tests/integration.updateDoc.func1()
        	            		/Users/keenan/Projects/defradb/tests/integration/utils2.go:1190 +0x80
        	            	github.com/sourcenetwork/defradb/tests/integration.withRetry({0x14000010068, 0x1, 0x140008353b8?}, 0x0, 0x14000835440)
        	            		/Users/keenan/Projects/defradb/tests/integration/utils2.go:1403 +0x90
        	            	github.com/sourcenetwork/defradb/tests/integration.updateDoc(0x14000a37a00, {{0x0, 0x0}, 0x0, 0x0, {0x14000041a40, 0x3d}, {0x105395e96, 0x2c}, 0x0})
        	            		/Users/keenan/Projects/defradb/tests/integration/utils2.go:1187 +0x2e0
        	            	github.com/sourcenetwork/defradb/tests/integration.executeTestCase({0x105aa7670?, 0x14000196018}, 0x14000a37860, {0x140004ba080, 0x2, 0x2}, {{0x1053b3d45, 0x44}, {0x1400052d680, 0x4, ...}, ...}, ...)
        	            		/Users/keenan/Projects/defradb/tests/integration/utils2.go:385 +0xf40
        	            	github.com/sourcenetwork/defradb/tests/integration.ExecuteTestCase(0x140004cfd50?, {{0x1053b3d45, 0x44}, {0x1400052d680, 0x4, 0x4}, {0x1, {0x140004ba060, 0x2, 0x2}}})
        	            		/Users/keenan/Projects/defradb/tests/integration/utils2.go:311 +0x504
        	            	github.com/sourcenetwork/defradb/tests/integration/mutation/update/field_kinds/one_to_many.executeTestCase(...)
        	            		/Users/keenan/Projects/defradb/tests/integration/mutation/update/field_kinds/one_to_many/utils.go:20
        	            	github.com/sourcenetwork/defradb/tests/integration/mutation/update/field_kinds/one_to_many.TestMutationUpdateOneToMany_InvalidAliasRelationNameToLinkFromManySide_Collection(0x1400015f230?)
        	            		/Users/keenan/Projects/defradb/tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go:255 +0x458
        	            	testing.tRunner(0x14000a37860, 0x105a8c758)
        	            		/usr/local/go/src/testing/testing.go:1576 +0x10c
        	            	created by testing.(*T).Run
        	            		/usr/local/go/src/testing/testing.go:1629 +0x368
        	            	FAIL	github.com/sourcenetwork/defradb/tests/integration/mutation/update/field_kinds/one_to_many	1.769s
        	            	FAIL

After some further digging I've verified that this test is not correctly persisting the document from the setup phase.

https://github.com/sourcenetwork/defradb/blob/develop/tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go#L231-L240

If this is a blocker for merging I can look into fixing it in a new PR.

@shahzadlone
Copy link
Member

I don't see that as a blocker as long as change detection works. Going to review one last time and give an LGTM in a few minutes

@nasdf
Copy link
Member Author

nasdf commented Sep 19, 2023

I don't see that as a blocker as long as change detection works. Going to review one last time and give an LGTM in a few minutes

For clarification #1897 fixed this failing test.

Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

LGTM

@shahzadlone
Copy link
Member

nitpick: Slight preference for the PR title to be a ci label, with first word as an action word. i.e. ci: Parallelize change detector

@nasdf nasdf changed the title test: Parallel change detector ci: Parallelize change detector Sep 19, 2023
@nasdf nasdf merged commit b8567c2 into sourcenetwork:develop Sep 19, 2023
14 checks passed
@nasdf nasdf deleted the nasdf/test/parallel-change-detector branch September 19, 2023 21:51
@nasdf nasdf mentioned this pull request Sep 27, 2023
11 tasks
nasdf added a commit that referenced this pull request Oct 2, 2023
## Relevant issue(s)

Closes #1472
Closes #1507
Closes #1860 

## Description

This is a follow up to #1776

This PR adds a CLI implementation that implements the client.DB
interface and runs through the existing integration test suite.

- [x] Merge existing server config code
- [x] Refactor CLI to use new HTTP client
- [x] Remove `net/api` package
- [x] Remove `api/http` package
- [x] Lens tests are timing out in CI: fixed #1862
- [x] Code coverage is incorrectly reporting: fixed #1861
- [x] Flaky test causing failures: fixed #1912

Renamed Commands:
- `peerid` to `client peer info`
- `client p2pcollection` to `client p2p collection`
- `client replicator` to `client p2p replicator`
- `client schema list` to `client collection describe`

Removed Commands:
- `block get`
- `ping`
- `rpc`

Added Commands:
- `client collection create`
- `client collection delete`
- `client collection get`
- `client collection keys`
- `client collection update`
- `client tx create`
- `client tx discard`
- `client tx commit`
- `client schema migration up`
- `client schema migration down`
- `client schema migration reload`

**Notes for reviewers**:
- `.github` changes are merged from #1871
- `Makefile` most of these changes are also from #1871
- `docs/cli` ignore these changes, it will be updated next release
- sorry for all of the merge commits, I am working on learning rebase
flow

## Tasks

- [x] I made sure the code is well commented, particularly
hard-to-understand areas.
- [x] I made sure the repository-held documentation is changed
accordingly.
- [x] I made sure the pull request title adheres to the conventional
commit style (the subset used in the project can be found in
[tools/configs/chglog/config.yml](tools/configs/chglog/config.yml)).
- [x] I made sure to discuss its limitations such as threats to
validity, vulnerability to mistake and misuse, robustness to
invalidation of assumptions, resource requirements, ...

## How has this been tested?

`make test`

Specify the platform(s) on which this was tested:
- MacOS
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
## Relevant issue(s)

Resolves sourcenetwork#1436

## Description

This PR allows the change detector to run in parallel with other tests.

There are also a few other improvements to the change detector:
- change detector logic is moved to a new `tests/change_detector`
package
- change detector specific logic in `tests/integration` is now more
obvious
- change detector now operates on distinct `source` and `target`
branches
- this enables you to test branches outside of the currently checked out
branch
- change detector manages its own environment variables. 
- running `go test ./tests/change_detector/...` will work without env
variables
- change detector temp directories are now all cleaned up after running

Todo before merging:
- [x] update default branch and repository
- [x] document change detector data format changes

## Tasks

- [x] I made sure the code is well commented, particularly
hard-to-understand areas.
- [x] I made sure the repository-held documentation is changed
accordingly.
- [x] I made sure the pull request title adheres to the conventional
commit style (the subset used in the project can be found in
[tools/configs/chglog/config.yml](tools/configs/chglog/config.yml)).
- [x] I made sure to discuss its limitations such as threats to
validity, vulnerability to mistake and misuse, robustness to
invalidation of assumptions, resource requirements, ...

## How has this been tested?

`make test:changes`

Specify the platform(s) on which this was tested:
- MacOS
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
## Relevant issue(s)

Closes sourcenetwork#1472
Closes sourcenetwork#1507
Closes sourcenetwork#1860 

## Description

This is a follow up to sourcenetwork#1776

This PR adds a CLI implementation that implements the client.DB
interface and runs through the existing integration test suite.

- [x] Merge existing server config code
- [x] Refactor CLI to use new HTTP client
- [x] Remove `net/api` package
- [x] Remove `api/http` package
- [x] Lens tests are timing out in CI: fixed sourcenetwork#1862
- [x] Code coverage is incorrectly reporting: fixed sourcenetwork#1861
- [x] Flaky test causing failures: fixed sourcenetwork#1912

Renamed Commands:
- `peerid` to `client peer info`
- `client p2pcollection` to `client p2p collection`
- `client replicator` to `client p2p replicator`
- `client schema list` to `client collection describe`

Removed Commands:
- `block get`
- `ping`
- `rpc`

Added Commands:
- `client collection create`
- `client collection delete`
- `client collection get`
- `client collection keys`
- `client collection update`
- `client tx create`
- `client tx discard`
- `client tx commit`
- `client schema migration up`
- `client schema migration down`
- `client schema migration reload`

**Notes for reviewers**:
- `.github` changes are merged from sourcenetwork#1871
- `Makefile` most of these changes are also from sourcenetwork#1871
- `docs/cli` ignore these changes, it will be updated next release
- sorry for all of the merge commits, I am working on learning rebase
flow

## Tasks

- [x] I made sure the code is well commented, particularly
hard-to-understand areas.
- [x] I made sure the repository-held documentation is changed
accordingly.
- [x] I made sure the pull request title adheres to the conventional
commit style (the subset used in the project can be found in
[tools/configs/chglog/config.yml](tools/configs/chglog/config.yml)).
- [x] I made sure to discuss its limitations such as threats to
validity, vulnerability to mistake and misuse, robustness to
invalidation of assumptions, resource requirements, ...

## How has this been tested?

`make test`

Specify the platform(s) on which this was tested:
- MacOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing Related to any test or testing suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move change detector target branch cloning out of init
3 participants