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

Rails routes being mounted counts as runtime line hits, but should be load time #543

Open
kieran-flex opened this issue Jun 26, 2024 · 3 comments

Comments

@kieran-flex
Copy link

Describe the bug
When doing "mount API:RootAPI => '/' at startup to mount all of our APIs in Rails (we use Grape for the actual APIs) then it cascades through all of the initialisation code in those Controllers an related code and includes them in coverage but marks it all as runtime.
It then makes it really hard to tell if an API is actually used because it says lots of code is used at runtime, when really none is and it is all just load time.
How is load time versus runtime worked out? Can I force anything that happens during route mounting to be considered load time?

Screenshots below:

Screenshot 2024-06-26 at 17 46 46 Screenshot 2024-06-26 at 17 48 04
@danmayer
Copy link
Owner

danmayer commented Jul 8, 2024

hmmm... so runtime vs loading is triggered based on when we think the full app has been eagerly loaded... this might be different for how grape hooks into routes... Does our app have eager_loading for rails, I would assume it loads all of your grape files at that time.... I know some graphql libraries have problems where most of the graph is defining a schema and not used at run time... I don't use grape, so I might need a small sample app or PR on the coverband_rails demo app reproducing the issue for me to fix it.

@harshanails
Copy link

We are using coverband in the context of mapping source code paths to E2E tests - for the purpose of selective execution of E2E tests in MR pipelines. Context MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/149950

In this I see a bunch of app/graphql/types/* paths mapped to almost all E2E tests. Even a log_in spec for example. Is this because the gitlab rails app eager loads all graphql types when application is launched?

@danmayer

@danmayer
Copy link
Owner

yeah I think there is issues with how some of the frameworks lazy load or load schemas and types... I haven't used grape for a long time so I don't know how exactly mount is loading things, but if it is lazy loading the code would end up at runtime vs loading... I have definitely seen this issue with graphql, when all the types get loaded after rails has finished initializing.

A few things to check:

  • ensure you have eager_load = true in whatever environment you are capturing coverband coverage.
  • read about Rails autoloading: https://guides.rubyonrails.org/autoloading_and_reloading_constants.html
  • specifically for grape and graphql look at these options to ensure they would cover your graphql types or grape apis folders
    • config.autoload_paths
    • config.eager_load_paths

Folks that have graphql or graph try it out and let me know. If there is a small repo that shows this issue I can try to debug it but I don't have a small reproducible code flow that shows this problem. Let me know @harshanails or @kieran-flex

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

No branches or pull requests

3 participants