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

Add integration tests #274

Merged
merged 30 commits into from
Aug 9, 2024
Merged

Add integration tests #274

merged 30 commits into from
Aug 9, 2024

Conversation

amishas157
Copy link
Contributor

@amishas157 amishas157 commented Aug 5, 2024

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with the jira ticket associated with the PR.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated the README with the added features, breaking changes, new instructions on how to use the repository. I updated the description of the fuction with the changes that were made.

Release planning

  • I've decided if this PR requires a new major/minor/patch version accordingly to
    semver, and I've changed the name of the BRANCH to release/_ , feature/_ or patch/* .

What

This PR adds integration tests for all the export_* commands. The changes comprise of following:

  • Existing runCLITest in cmd/export_ledgers_test.go is used to run all test files in cmd.
  • update=true flag is supported to update golden files automatically.
  • More tests suites are added for export_ledger_entry_changes_test. This is to cover all kinds of ledger entry changes listed in https://github.com/stellar/stellar-etl?tab=readme-ov-file#unbounded-currently-unsupported
  • Updated all the outdated golden files.
  • A docker file is added to run tests. Current docker file does not have context of /cmd.
  • A docker-compose file is added to start a docker compose service with right gcp creds and run the tests.
  • Github workflow is added to run integration test, find code coverage and a threshold check for coverage
  • Updated github workflows to cancel any previous jobs if new commits are pushed
  • Updated Readme and Makefile for helper with running the tests.
  • A secret CREDS_TEST_HUBBLE is added to this repo which has access to bigquery and storage bucket. This is used by integration test to read ledger backend data

Why

To gain confidence in feature addition or bug fix, integration tests are required.

Known limitations

None

Test Results:

  • Running integration test takes ~3 minutes.
    Screenshot 2024-08-08 at 5 39 08 PM
  • Our current test coverage is 57% and I have setup a threshold of 55%
    Screenshot 2024-08-08 at 5 39 51 PM
  • Commit intentionally failed to verify failure 1d39d47

@amishas157
Copy link
Contributor Author

How I ran the tests:

  • docker-compose build
  • docker-compose run integration-tests go test -run ^TestExport ./cmd -timeout 30m -args -update=true

add secret as env variable in github workflow

remove env from docker compose
@amishas157 amishas157 force-pushed the integration-test branch 8 times, most recently from 2eae7f7 to de8c133 Compare August 8, 2024 19:46
mount file and pass env

remove extra env

temp

cat temp

empty

printf

rearrange

validate json

workaround

cleanup

verbose
Fix coverage report

coverage fix
@amishas157 amishas157 changed the title Boiler plate Add integration tests Aug 8, 2024
@amishas157 amishas157 marked this pull request as ready for review August 8, 2024 22:40
@amishas157 amishas157 requested a review from a team as a code owner August 8, 2024 22:40
Comment on lines -64 to -76
wantErr: fmt.Errorf("could not read ledgers: End sequence number is less than start (50 < 100)"),
},
{
name: "start too large",
args: []string{"export_ledgers", "-s", "4294967295", "-e", "4294967295"},
golden: "",
wantErr: fmt.Errorf("could not read ledgers: Latest sequence number is less than start sequence number (%d < 4294967295)", latestLedger),
},
{
name: "end too large",
args: []string{"export_ledgers", "-e", "4294967295", "-l", "4294967295"},
golden: "",
wantErr: fmt.Errorf("could not read ledgers: Latest sequence number is less than end sequence number (%d < 4294967295)", latestLedger),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are flaky test. Therefore I removed them

Comment on lines +126 to +145
idxOfOutputArg := indexOf(test.args, "-o")
var testOutput []byte
var outLocation string
var stat os.FileInfo
if idxOfOutputArg > -1 {
outLocation = test.args[idxOfOutputArg+1]
_, err = os.Stat(outLocation)
if err != nil {
// Check if the error is due to the file not existing
if !os.IsNotExist(err) {
assert.NoError(t, err)
}
} else {
err = deleteLocalFiles(outLocation)
if err != nil {
log.Fatal(err)
}
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to delete anything in the output directory before exporting any data.

Copy link
Contributor

@sydneynotthecity sydneynotthecity left a comment

Choose a reason for hiding this comment

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

This looks great!

I have a couple questions for my own understanding before approving. I also glanced over the golden set files briefly, but i'm assuming they are valid since the integration tests succeed.

.github/workflows/integration-tests.yml Show resolved Hide resolved
.github/workflows/integration-tests.yml Show resolved Hide resolved
cmd/export_contract_events_test.go Outdated Show resolved Hide resolved
cmd/export_ledger_entry_changes_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we'll run into any issues using different ledger ranges to generate these files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. There can be issues if code has bug for different kind of input. Since the ledger range can contain only certain variety of data. It may not cover for all test cases.

I had a thought to have custom fixtures along with ledger range test cases. But I think that's already part of our unit tests. so we should be good generally.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a good enough start point and if we run into edge cases, we can always either adjust the ledger ranges or add custom fixtures as you suggested

cmd/export_ledgers_test.go Outdated Show resolved Hide resolved
cmd/export_ledgers_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@sydneynotthecity sydneynotthecity left a comment

Choose a reason for hiding this comment

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

LGTM

@amishas157 amishas157 merged commit c7991a5 into master Aug 9, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants