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

chore(test): run go interop tests in the same rust process #4636

Merged
merged 12 commits into from
Aug 15, 2024

Conversation

hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Aug 9, 2024

Summary of changes

This PR uses rust2go to invoke the go-kad test app in the rust process, to demonstrate how FFI for the f3 sidecar works.

Note that go1.21.x is required to run forest-interop-test

Changes introduced in this pull request:

  • Move go-kad compact test to forest-interop-test and invoke with rust2go
  • Move go-bitswap compact test to forest-interop-test and invoke with rust2go
  • Update CI workflow and Makefile accordingly

Test result on CI: https://github.com/ChainSafe/forest/actions/runs/10355850383/job/28664406918?pr=4636#step:6:2191

        PASS [   1.077s] forest-interop-tests tests::bitswap_go_compat::bitswap_go_compat_test
        PASS [   2.859s] forest-filecoin::lint lint
        PASS [   1.131s] forest-interop-tests tests::kad_go_compat::kad_go_compat_test

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@hanabi1224 hanabi1224 force-pushed the hm/run-go-kad-compat-test-in-same-process branch from 972ca4a to cf560ae Compare August 9, 2024 15:56
@hanabi1224 hanabi1224 marked this pull request as ready for review August 9, 2024 15:57
@hanabi1224 hanabi1224 requested a review from a team as a code owner August 9, 2024 15:57
@hanabi1224 hanabi1224 requested review from lemmih and LesnyRumcajs and removed request for a team August 9, 2024 15:57
@hanabi1224 hanabi1224 marked this pull request as draft August 12, 2024 08:53
@hanabi1224 hanabi1224 force-pushed the hm/run-go-kad-compat-test-in-same-process branch from 6b9598c to 920d40e Compare August 12, 2024 11:12
@hanabi1224 hanabi1224 force-pushed the hm/run-go-kad-compat-test-in-same-process branch from 920d40e to f3c1ca9 Compare August 12, 2024 11:20
@hanabi1224 hanabi1224 changed the title chore(test): run go-kad compat test in the same rust process chore(test): run go interop tests in the same rust process Aug 12, 2024
@hanabi1224 hanabi1224 marked this pull request as ready for review August 12, 2024 16:49
}

#[derive(rust2go::R2G, Clone, Default)]
pub struct EmptyReq {}
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 required due to a bug ihciah/rust2go#10

Copy link
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

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

The end binary doesn't require go, right? That is to say, if we ship the forest binary, there are no extra requirements (except the ones that are already listed in the Dockerfile)?

package main

/*
// Generated by rust2go. Please DO NOT edit this C part manually.
Copy link
Member

Choose a reason for hiding this comment

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

Should the generated file be included in the version control?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm neutral about it. It's not required but makes code readable for users who solely browse the repo. What's your recommendation?

Copy link
Member

Choose a reason for hiding this comment

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

Pros:

  • any change to it must be reviewed,
  • somehow searchable.

Cons:

  • will the changes to this file be actually reviewed or just blindly approved, especially when it'll be some obscure Go with C code?
  • it introduces some noise, e.g., simple Cargo.toml or lockfiles are easily approved,
  • while it allows some searching, it will also make general grepping more difficult - in my workflow, I'd need to disable looking in .go files to avoid noise.

All in all, if it's trivial to generate, I'd generate it on the fly and not add it to the version control.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

interop-tests/Cargo.toml Outdated Show resolved Hide resolved
@hanabi1224
Copy link
Contributor Author

hanabi1224 commented Aug 13, 2024

The end binary doesn't require go, right? That is to say, if we ship the forest binary, there are no extra requirements (except the ones that are already listed in the Dockerfile)?

@LesnyRumcajs Yes, no extra dependencies(unless go-f3 dynamically links to other libs). BTW, this change happens to a publish=false test crate. We only need rust2go in forest when shipping f3 feature

@hanabi1224 hanabi1224 force-pushed the hm/run-go-kad-compat-test-in-same-process branch from 428d3f1 to 8303f88 Compare August 13, 2024 10:36
@hanabi1224 hanabi1224 added this pull request to the merge queue Aug 15, 2024
Merged via the queue into main with commit 2aafa4b Aug 15, 2024
30 checks passed
@hanabi1224 hanabi1224 deleted the hm/run-go-kad-compat-test-in-same-process branch August 15, 2024 05:27
@ihciah
Copy link

ihciah commented Aug 23, 2024

Hi! I'm the author of rust2go. Thank you for choosing rustgo! In out production environment we have validated its relibility.

One thing to note is that, remember to add GODEBUG=invalidptr=0,cgocheck=0 env when run it, otherwise there maybe panic invalid pointer found on stack in go side when it tries to grow the goroutine stack(related code). This env can also be added with golang code on init: os.Setenv("GODEBUG", ...).

For testing, it doesn't matter whether there is this environment variable or not. But if you use it to serve requests, remember to add it.

@hanabi1224
Copy link
Contributor Author

Hi! I'm the author of rust2go. Thank you for choosing rustgo! In out production environment we have validated its relibility.

One thing to note is that, remember to add GODEBUG=invalidptr=0,cgocheck=0 env when run it, otherwise there maybe panic invalid pointer found on stack in go side when it tries to grow the goroutine stack(related code). This env can also be added with golang code on init: os.Setenv("GODEBUG", ...).

For testing, it doesn't matter whether there is this environment variable or not. But if you use it to serve requests, remember to add it.

@ihciah Thank you for the hints, this has been addressed in #4682

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.

4 participants