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

e2e_test: integrate MistLoadTest to verify streaming #54

Merged
merged 3 commits into from
Aug 2, 2022

Conversation

emranemran
Copy link
Contributor

Use MistLoadTest to spawn multiple clients for a specific protocol (e.g. HLS) as viewers at catalyst-two node. The test passes if every client is able to connect and stream successfully. The json files generated by MistLoadTest are parse to verify if streams passed or failed.

@emranemran emranemran requested review from iameli and leszko July 21, 2022 19:20
@emranemran emranemran force-pushed the user/emahbub/integrate-mistloadtest-e2e branch from 172c504 to 73bb142 Compare July 21, 2022 19:27
@emranemran emranemran force-pushed the user/emahbub/integrate-mistloadtest-e2e branch from 73bb142 to 67d8ad2 Compare July 21, 2022 19:32

matches, err := filepath.Glob("*" + strings.ToUpper(prot) + "*json")
if err != nil {
panic(fmt.Errorf("Glob failed: %w", err))
Copy link
Member

Choose a reason for hiding this comment

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

Will defer to @leszko here on best practices for tests like this, but should this maybe be returning an error instead of panicking? Seems like a good practice in general... on the other hand I can see how this error would be like "test harness failure" instead of "failing test" and maybe a panic makes sense there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'm inclined to remove the panic and just make it a general "fail". We'd be reviewing logs anyways to see where the failures are - doesn't seem like a panic would be anymore useful here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, better to not use panic in tests. You can do t.Fail() instead.


content, err := ioutil.ReadFile(matches[0])
if err != nil {
glog.Fatalf("Error while opening output file: %s", err)
Copy link
Member

Choose a reason for hiding this comment

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

In any event, no sense in doing anything else after a Fatalf, which will crash the process immediately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I realize that now after looking at the Fatalf man page which calls os.Exit right after. Will fix.

return true
}
require.Eventually(t, correctStream, 5*time.Minute, time.Second)

// Define a set of protocols to test at output of node catalyst-two
protocols := map[string]string{
Copy link
Member

Choose a reason for hiding this comment

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

Nice! I'm thinking that each protocol should probably be its own test, rather than just having one big loop in here? Minimally, having a separate function for running a protocol test will let you return err in the error cases for those instead of having to do awkward continues or breaks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I think I got a little lost in trying to do things in the "idiomatic" go style. I'll take a look at refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it should be a separate test. Also, the very idiomatic in Go is to use a tests [] array. Please check "Introducing table driven tests" in https://dave.cheney.net/2019/05/07/prefer-table-driven-tests

Copy link
Member

@iameli iameli left a comment

Choose a reason for hiding this comment

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

Really really nice! Happy it wasn't too terrible to get this working properly - just suggested a few structuring changes

@emranemran emranemran force-pushed the user/emahbub/integrate-mistloadtest-e2e branch from 67d8ad2 to c3ca3ca Compare July 22, 2022 06:17
Copy link
Contributor

@leszko leszko left a comment

Choose a reason for hiding this comment

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

Added some comments. But two general thoughts:

  1. We should create more tests rather than expanding the assertion of the same test. Having more tests give us better information what failed. One single test is hard to analyze in case of failures.
  2. I'd try to not cleanup files manually, but rather depend on the built-in 1t.TempDir()

return true
}
require.Eventually(t, correctStream, 5*time.Minute, time.Second)

// Define a set of protocols to test at output of node catalyst-two
protocols := map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it should be a separate test. Also, the very idiomatic in Go is to use a tests [] array. Please check "Introducing table driven tests" in https://dave.cheney.net/2019/05/07/prefer-table-driven-tests

}

// rm any old output files from previous MistLoadTest runs
cleanupFiles("*json")
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to store all these files in the t.TempDir(), then the files are automatically removed after the test is completed.

Manually removing the files has some disadvantages, e.g., if the test fails, then we can end up with uncleaned files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'll have to update MistLoadUtil to accept a different path. But agree managing files is not the best way - didn't know about t.TempDir() so i'll try to get that to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR here to allow output directory:
DDVTECH/mistserver@1341ffb

This should let me refactor into something much simpler.


glog.Infof("Testing %s using url: %s", prot, url)

cmdMistLoadTest := exec.Command("../../bin/./MistLoadTest", url)
Copy link
Contributor

Choose a reason for hiding this comment

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

As already commented above, I think this should be a completely separate test, not to add too many things in one test. In general, it's better to have more smaller tests, than one very big test.

}
glog.Infof("MistLoadTest stdout: %s", out)

defer cmdMistLoadTest.Process.Kill()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that this process is not killed and we end up with a running MistLoadTest process? E.g. what happens if the line 250 fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MistLoadTest will timeout and exit within 30s (default). I'll turn it into a parameter in the next push and verify it does work as expected.

}

// Parse output results for each protocol tested above
var p bool = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var p bool = true
p := true


matches, err := filepath.Glob("*" + strings.ToUpper(prot) + "*json")
if err != nil {
panic(fmt.Errorf("Glob failed: %w", err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, better to not use panic in tests. You can do t.Fail() instead.

}
fmt.Println(matches)

content, err := ioutil.ReadFile(matches[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

What if there are multiple files that are matched? Like there is already another *.json file in the directory?

if err != nil {
panic(fmt.Errorf("Glob failed: %w", err))
}
fmt.Println(matches)
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to glog

@emranemran emranemran force-pushed the user/emahbub/integrate-mistloadtest-e2e branch 2 times, most recently from 0ad11df to dc7fd92 Compare July 29, 2022 04:27
@emranemran emranemran changed the base branch from main to rafal/playback-redirection July 29, 2022 04:28
@emranemran emranemran changed the base branch from rafal/playback-redirection to main July 29, 2022 04:33
@emranemran emranemran force-pushed the user/emahbub/integrate-mistloadtest-e2e branch 2 times, most recently from 0ad11df to 5cc69cd Compare July 29, 2022 04:46
@emranemran emranemran requested review from leszko and iameli July 29, 2022 04:47
@emranemran
Copy link
Contributor Author

Updates:

  • Refactored to use table driven test as suggested by @leszko. We can now run a load test against each protocol (e.g. HLS) independently or all protocols at the same time as defined in the test matrix
  • Using t.TempDir() to get simplify code that tracked/deleted results files
  • Blocked on merging until @leszko's PR for redirection merges as I need to rebase on that branch to pick up some changes to e2e_test.go

Copy link
Contributor

@leszko leszko left a comment

Choose a reason for hiding this comment

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

Added some minor comments. Other than that, it looks good. Thanks for all the changes @emranemran 👍

test/e2e/e2e_test.go Outdated Show resolved Hide resolved
test/e2e/e2e_test.go Outdated Show resolved Hide resolved
test/e2e/e2e_test.go Show resolved Hide resolved
@emranemran emranemran force-pushed the user/emahbub/integrate-mistloadtest-e2e branch 8 times, most recently from 8acd8d7 to f3e6cda Compare August 1, 2022 19:06
Use MistLoadTest to spawn multiple clients for a specific protocol (e.g. HLS)
as viewers at catalyst-two node. The test passes if every client is able to
connect and stream successfully. The json files generated by MistLoadTest
are parsed to verify if streams passed or failed.
@emranemran emranemran force-pushed the user/emahbub/integrate-mistloadtest-e2e branch from 0a38628 to 3169383 Compare August 2, 2022 22:02
…I host

The Mist tester binaries need to run outside of the containers or inside another
container. This is a temporary workaround to run outside the containers directly
on the CI host. This is obviously a bit fragile and a follow up change will be used
to make this more robust by using a third container that contains all relevant test
binaries
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.

None yet

3 participants