dropbox / dbx_build_tools

Dropbox's Bazel rules and tools
Other
208 stars 36 forks source link

Question: Using dbx_service_task to generate data for dbx_services_test #15

Closed mojkos closed 3 years ago

mojkos commented 3 years ago
  1. Problem description:
    • We have integration test which requires an input data
    • Input data is result of python binary execution wrapped with dbx_service_task, it executes some actions and produce hash in a file as result for those actions
    • We want that file be accessible in test's context.
    • Currently, dbx_service_task does NOT declare any output so there's nothing to declare as 'data' dependency for test.
  2. Questions:
    • Do you have similar use cases, and how did you handle them?
    • If not, what do you think is the way to pass files created by the service task into context of dbx_service_test target?
dzbarsky commented 3 years ago

Hi @mojkos,

There's 2 easy ways to accomplish what you want:

  1. If the data your python binary needs is deterministic and available in the repository, you could use a genrule instead of a dbx_service_task to produce the hash file. Genrules create output for other rules to consume in their data attributes (the output would be located in runfiles). This would result in the binary running once and having the result be cached, rather than with every test invocation.
  2. You can use the services attribute of a test rule to depend on your existing dbx_service_task rule. This would result in your task running as a prerequisite every time your test runs.

Hope that helps!

mojkos commented 3 years ago

Thanks @dzbarsky.

That's something I was expecting, just wanted to hear some other thoughts on that.