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

RSDK-9087 Test setup phase #4483

Merged

Conversation

maximpertsov
Copy link
Member

@maximpertsov maximpertsov commented Oct 23, 2024

Summary

Add basic tests for for first run, mainly asserting based on expected logs. Test the following scenarios, in order:

  1. first run fails
  2. first run succeeds
  3. first run skips on subsequent call
  4. first run skips on subsequent call, even if module manager is restarted

In addition, this PR refactors the BuildTempModule helper for clarity.

Prerequisites

TODO

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 23, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 24, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 25, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 25, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 25, 2024
@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Oct 29, 2024
Copy link
Member

@cheukt cheukt left a comment

Choose a reason for hiding this comment

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

looks good! some questions and suggestions

@@ -248,6 +249,7 @@ func (m Module) EvaluateFirstRunPath(packagesDir string) (

firstRunSuccessPath := unpackedModDir + FirstRunSuccessSuffix
if _, err := os.Stat(firstRunSuccessPath); !errors.Is(err, os.ErrNotExist) {
logger.Info("first run already ran")
Copy link
Member

Choose a reason for hiding this comment

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

will this not be double logged?

Copy link
Member Author

Choose a reason for hiding this comment

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

it shouldn't - where do you see potential for a double log?

Copy link
Member

Choose a reason for hiding this comment

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

because it returns an error saying the same thing - just wondering, wasn't sure if that would happen

Copy link
Member Author

Choose a reason for hiding this comment

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

oh yeah, sorry you are right - the error from this function is logged at the debug level, so we get a double log in that scenario. this should get cleared up when we refactor this function. the current contract requires we return an error here to prevent first run logic from firing. we can change the text in the error to prevent a double-log in the meantime.

Copy link
Member Author

Choose a reason for hiding this comment

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

since it only happens during debug, I think it's better to address during the upcoming refactor PR

module/modmanager/manager_test.go Outdated Show resolved Hide resolved
module/modmanager/manager_test.go Outdated Show resolved Hide resolved
module/modmanager/manager_test.go Outdated Show resolved Hide resolved
#!/usr/bin/env bash

if [[ -n "$VIAM_TEST_FAIL_RUN_FIRST" ]]; then
>&2 echo "erroring... 1"
Copy link
Member

Choose a reason for hiding this comment

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

can you add a comment to that effect?

testutils/file_utils.go Show resolved Hide resolved
testutils/file_utils.go Outdated Show resolved Hide resolved
@maximpertsov
Copy link
Member Author

sorry, which comment/effect are you referring to here?

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 29, 2024
two other changes:

* clarify docs near logs.TakeAll()
* handle unsetting environment variables in between sections
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 29, 2024
Copy link
Member

@cheukt cheukt left a comment

Choose a reason for hiding this comment

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

testutils/file_utils.go Show resolved Hide resolved
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 29, 2024
@maximpertsov
Copy link
Member Author

was referring to https://github.com/viamrobotics/rdk/pull/4483/files#r1815872127

made a function to clarify what's going on: 9f4a614

Copy link
Member

@cheukt cheukt left a comment

Choose a reason for hiding this comment

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

generally looks good, can you use wait groups so that the stdout and stderr workers are properly awaited?

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 29, 2024
@maximpertsov
Copy link
Member Author

generally looks good, can you use wait groups so that the stdout and stderr workers are properly awaited?

done ee08599. unfortunately we still need to sleep in the script for tests to pass - i was hoping this would remove the need :(

Copy link
Member

@cheukt cheukt left a comment

Choose a reason for hiding this comment

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

LGTM!

// resulting executable binary into a temporary directory. If successful, this function will
// return the path to the executable binary.
func BuildTempModule(tb testing.TB, modDir string) string {
// tb.Helper()
Copy link
Member

Choose a reason for hiding this comment

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

can you revert these

// and "first_run.sh" into the same temporary directory. It is assumed that these files are in the
// provided module directory. If successful, this function will return the path to the executable binary.
func BuildTempModuleWithFirstRun(tb testing.TB, modDir string) string {
// tb.Helper()
Copy link
Member

Choose a reason for hiding this comment

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

plus this

@maximpertsov
Copy link
Member Author

#4483 (comment)

ugh, yes great catch. I was briefly debating whether it's worth removing this permanently so we can see exactly which lines of this helper fail. However, that goes against the idea of a helper function and will probably make tests that use it harder to debug in the future.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 30, 2024
@maximpertsov maximpertsov merged commit be6f595 into viamrobotics:main Oct 30, 2024
18 checks passed
@maximpertsov maximpertsov deleted the RSDK-9087-test-setup-phase branch October 30, 2024 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants