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

Andrew7234/api tests #360

Merged
merged 27 commits into from
Apr 26, 2023
Merged

Andrew7234/api tests #360

merged 27 commits into from
Apr 26, 2023

Conversation

Andrew7234
Copy link
Collaborator

@Andrew7234 Andrew7234 commented Mar 20, 2023

https://app.clickup.com/t/861md6gue

Test flow:

  • make dump-state: dumps consensus node state requests to file using pogreb
  • make test-api: runs a fresh indexer according to the params in api-dev.yml using the file-based consensus node state created in the previous step. Then runs the e2e api tests to find the diff between the expected responses (generated previously and checked into github) and the actual responses from the indexer.

The initial idea of this PR is to

  • Update the indexer to be able to read node data from a file to facilitate e2e testing offline or in CI without access to a node
  • To support ^, add a tool to dump node state into a file
  • Add api tests that utilize the existing run.sh tool to verify both analyzer and indexer api functionality

Open questions/todos:

  • Runtime support in this PR? or a later one [added]
  • Add to CI [deferring to later pr]
  • rip out the hacky config stuff and replace with a custom file config after 352 goes in [done]

storage/oasis/nodeapi/file/node.go Outdated Show resolved Hide resolved
storage/oasis/nodeapi/file/node.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mitjat mitjat left a comment

Choose a reason for hiding this comment

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

Nice! Really curious about the speed of running the analyzer against the cached data.

Also, looks like you already intended to split it this way, but let's worry about integrating this into CI in a separate PR.

tests/api/data/consensus/00000-1.psg Outdated Show resolved Hide resolved
tests/api/api-dev.yml Outdated Show resolved Hide resolved
storage/oasis/nodeapi/file/node.go Outdated Show resolved Hide resolved
storage/oasis/nodeapi/file/node.go Outdated Show resolved Hide resolved
storage/oasis/nodeapi/file/node.go Outdated Show resolved Hide resolved
storage/oasis/consensus.go Outdated Show resolved Hide resolved
tests/api/util_test.go Outdated Show resolved Hide resolved
tests/e2e_regression/run.sh Outdated Show resolved Hide resolved
tests/e2e_regression/run.sh Outdated Show resolved Hide resolved
while ! curl --silent localhost:8008/v1/ >/dev/null; do
echo "Waiting for API server to start..."
sleep 1
done

# Run the test cases.
seen=()
seen=("placeholder") # avoids 'seen[*]: unbound variable' error on zsh
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: because of the #!/bin/bash shebang, don't you have to go to extra trouble to run this in zsh? Alternatively, is there an invocation where you can explicitly invoke the script with bash and avoid zsh compat issues?

config/config.go Outdated Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@Andrew7234 Andrew7234 requested a review from mitjat April 20, 2023 15:14
Copy link
Contributor

@mitjat mitjat left a comment

Choose a reason for hiding this comment

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

Thank you! I left only one more not-entirely-trivial comment, but I think it's not contentious either.

Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
config/config.go Show resolved Hide resolved
storage/oasis/client.go Show resolved Hide resolved
storage/oasis/client.go Show resolved Hide resolved
@mitjat
Copy link
Contributor

mitjat commented Apr 25, 2023

Reviewing the code made me wonder if it can be written with less repetition. My proof of concept ended up working out; I pushed it to this PR as three additional commits. Benefits of the slight refactor:

  • less code + less repetition
  • for calls where the value is not yet in the cache, avoids deserialization
    Downside: Potentially hared-to-understand code?

I only made the changes on the consensus side; I feel the runtime side has too few methods to warrant generalizing them. Although I guess the whole getFromCacheOrCall() could be moved into a new KVStore struct that is an abstraction over pogreb; a good idea regardless in case we want to mock or replace pogreb later.

Disclaimer: This is untested beyond satisfying the compiler. And we don't have the habit of slipping into each other's PRs. So I'm happy to submit this as a follow-up PR too, or we can leave it as a part of this one, whichever you prefer.

@mitjat
Copy link
Contributor

mitjat commented Apr 25, 2023

Uh a pretty big problem I noticed: the docs for pogreb.Open() state: "opens or creates a new DB. The DB must be closed after use, by calling Close method."
We'll have to give a Close() or Shutdown() method to ApiLite structs and analyzers and pipe that through to pogreb :/. Otherwise, it sounds like we're risking data corruption.

@mitjat
Copy link
Contributor

mitjat commented Apr 25, 2023

the whole getFromCacheOrCall() could be moved into a new KVStore struct that is an abstraction over pogreb

Done that now, and also simplified the runtime FileApiLite.

Will work on the Close() problem tomorrow.

@Andrew7234 Andrew7234 merged commit dc3834f into main Apr 26, 2023
@Andrew7234 Andrew7234 deleted the andrew7234/api-tests branch April 26, 2023 17:07
@@ -248,7 +248,7 @@ func registerTokenDecrease(tokenChanges map[TokenChangeKey]*big.Int, contractAdd
change.Sub(change, amount)
}

func ExtractRound(blockHeader nodeapi.RuntimeBlockHeader, txrs []*nodeapi.RuntimeTransactionWithResults, rawEvents []*nodeapi.RuntimeEvent, logger *log.Logger) (*BlockData, error) { //nolint:gocyclo
func ExtractRound(blockHeader nodeapi.RuntimeBlockHeader, txrs []nodeapi.RuntimeTransactionWithResults, rawEvents []nodeapi.RuntimeEvent, logger *log.Logger) (*BlockData, error) { //nolint:gocyclo
Copy link
Collaborator

Choose a reason for hiding this comment

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

what did these * removals do? originally they were pointers so that we don't have to copy structs around. not that that's particularly expensive.

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh it's so that we don't need a zillion different GetFromCacheOrCall variants, right?

@@ -90,6 +91,16 @@ func Ptr[T any](v T) *T {
return &v
}

// Returns `v` as a JSON string. If `v` cannot be marshaled,
// returns the string "null" instead.
func TryAsJSON(v interface{}) json.RawMessage {
Copy link
Collaborator

Choose a reason for hiding this comment

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

didn't this appear in an earlier PR? what happened to that? now I can't find it

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh that was #382, turns out it never got merged

@pro-wh
Copy link
Collaborator

pro-wh commented Apr 26, 2023

nice, thanks!

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.

3 participants