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

ingest/ledgerbackend: Refactor stellarCoreRunner #4480

Merged
merged 9 commits into from
Jul 29, 2022

Conversation

bartekn
Copy link
Contributor

@bartekn bartekn commented Jul 26, 2022

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 name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

This commit refactors stellarCoreRunner to allow writing unit tests that does not call fs/os functions and adds unit tests for new functionality added in 4850d22. It also changes newStellarCoreRunner by removing mode argument. The value will be set internally based on method calls.

Why

Code and test infrastructure improvements.

Known limitations

[TODO or N/A]

@bartekn bartekn marked this pull request as ready for review July 26, 2022 15:09
@bartekn bartekn requested a review from a team July 26, 2022 15:09
// We also want to use random directories in offline mode (reingestion)
// because it's possible it's running multiple Stellar-Cores on a single
// machine.
return path.Join(r.storagePath, "captive-core-"+createRandomHexString(8))
Copy link
Contributor

Choose a reason for hiding this comment

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

are the comments, ln 196-204, still relevant for windows o/s, it looks like this would prevent windows o/s deployments from re-using the same storage path in runFrom correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, Windows is unable to shutdown internal process gracefully so in most cases sqlite DB is just broken after shutdown.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, ok, should the entry for this change be added to Changelog.MD now, to mention this additional aspect that windows is not supported o/s for this optimization of re-using core's state db?

// removeAll not called
runner.systemCaller = scMock

assert.NoError(t, runner.runFrom(100, "hash"))
assert.NoError(t, runner.close())
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe assert on storage path persistence after close, assert.DirExists(t, runner.StoragePath)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if we should do that because after calling close the stellarCoreRunner instance shouldn't be reused. So we don't care about it's internal state anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

the intent is to assert core's stellar.dbwhich resides on disk's runner.StoragePath is not deleted after shutdown of runner correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I misread the assertion as checking if runner.StoragePath is empty. Anyway, we don't need to do that because we ensure that mocked systemCaller.removeAll is not called. assert.DirExists checks if there's a real file in real filesystem. All of the filesystem calls in this test are mocked so no files are created during the test.

@bartekn
Copy link
Contributor Author

bartekn commented Jul 27, 2022

@sreuland PTAL.

Copy link
Contributor

@sreuland sreuland left a comment

Choose a reason for hiding this comment

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

great test coverage!

@bartekn bartekn merged commit e3d3abc into master Jul 29, 2022
@bartekn bartekn deleted the stellarcorerunner-refactoring branch July 29, 2022 11:23
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