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

Automated smoke test that mimics user behavior UI and CLI #4393

Open
alexmt opened this issue Sep 22, 2020 · 23 comments
Open

Automated smoke test that mimics user behavior UI and CLI #4393

alexmt opened this issue Sep 22, 2020 · 23 comments
Assignees
Labels
component:test Test requests (e2e or unit) enhancement New feature or request help wanted Extra attention is needed

Comments

@alexmt
Copy link
Collaborator

alexmt commented Sep 22, 2020

Summary

We need an automated test that simulates user behavior and can be run to catch transient errors related to racing conditions in code.

Proposal

  • Implement an automation script that periodically re-creates and synchronizes a specified number of Argo CD applications.
  • It should be possible to configure application project, source and destination
  • The script should support CLI and UI mode:
    • CLI mode creates sync and deletes applications using argocd app create/argocd app sync/argocd app wait commands
    • UI mode uses webdriver and headless chrome
@alexmt alexmt added the enhancement New feature or request label Sep 22, 2020
@alexmt alexmt added this to the v1.8 milestone Sep 22, 2020
@jessesuen jessesuen added the help wanted Extra attention is needed label Sep 22, 2020
@keithchong
Copy link
Contributor

keithchong commented Oct 10, 2020

Hi @alexmt, @jessesuen , I could start on the initial automated UI tests using selenium-webdriver. This item could be divided into a couple of child items IMHO. Please assign this to me for now.

@dewan-ahmed
Copy link
Contributor

I can take on the CLI testing part. @jessesuen please let me know if there will be a separate task for CLI testing.

@alexmt
Copy link
Collaborator Author

alexmt commented Oct 14, 2020

Ops, missed your message @keithchong . Please go ahead.

@dewan-ahmed is it ok to use this ticket to track CLI and UI testing, and coordinate in comments? I can create separate ticket otherwise .

@dewan-ahmed
Copy link
Contributor

Hi @alexmt that's fine; I'll use this same issue to ask questions and track the work.

@jessesuen jessesuen added the component:test Test requests (e2e or unit) label Oct 14, 2020
@dewan-ahmed
Copy link
Contributor

These are the steps I'm planning for CLI testing part:

Pseudo script for argocd app create

  1. On a container, install all pre-reqs including k3d and spin up an argocd instance.
  2. execute argocd app create
  3. From the docs, understand what could be the validation after the above command executes e.g. some specific pods would be created. The script will query for those resources for the test to pass/fail.

@alexmt please advise.

@dewan-ahmed
Copy link
Contributor

@alexmt is the assumption that argocd is already installed and the user/session is connected to a K8s cluster? Or do we need to install the req'd dependency within the script?

@dewan-ahmed
Copy link
Contributor

dewan-ahmed commented Oct 16, 2020

This is the verification I'm thinking for argocd app create:

  1. argocd app list --insecure checking if an app with already exists. If yes, exist the program and request the user to delete existing app.
  2. If an app with does not exist, execute:
    argocd app create <some-app-name> --repo <some-repo-name>.git --path <some-path> --dest-server https://kubernetes.default.svc --dest-namespace default --insecure
  3. `argocd app list --insecure | grep "< some-app-name >" && echo "test passed" '

This is the verification I could think of. Please suggest other verifications I could do for this scenario.

@dewan-ahmed
Copy link
Contributor

Another approach for CLI testing would be to have source code level testing added here

@keithchong
Copy link
Contributor

keithchong commented Oct 23, 2020

Hi @alexmt , just wanted to give you an update.

Here's a 480p video that demonstrates the test in action.

  • Create the app
  • Sync it
  • Wait for status flags (Healthy and Synced - see console on right side of the video)
  • Delete the app
  • Wait for the delete operation to complete

This can also be run in headless mode (no browser is launched).

initialUiTest-480p.zip

Any feedback is appreciated.

Points to consider and possible follow-on enhancements

  • Need to customize it so you can specify any number of apps to be created. Right now it is just one app.
  • Add better error handling (edit: I added more to this in the PR. Stack traces are now more meaningful.)
  • Add better validation/verification after each step
  • Use mocha; launch a test suite of tests
  • the CLI will still need to be created to invoke the UI test or launch the test suites.
  • Add better error recovery. eg. how to return to the base state, say, no applications in the list, after one test is run but failed. and an app hasn't been deleted.

For the first point, if multiple apps are shown in the application list, there needs to be a way to correctly identify the Sync or Delete button in the tile of the desired app.

@dewan-ahmed
Copy link
Contributor

dewan-ahmed commented Oct 25, 2020

This is myworking file for the first test - app creation. Per the discussion from community call, these are my assumptions:

  • argocd cli is installed
  • argocd server variable is set
  • argocd cli is authenticated with username 'admin'

However, I'm getting the following error when running my test script:
time="2020-10-25T19:35:20-04:00" level=fatal msg="rpc error: code = Unauthenticated desc = Invalid username or password"

From my understand on the community call discussion, I should not be worrying about the authentication part and should assume that the session is already authenticated.

What I've tried:

  • Added another code block above the first RunCli to authenticate. Still same error.
  • Tried adding EnsureCleanState(t) code block beforehand. Still same error.

Please let me know if I can try something else to ensure I can properly test this code on my local environment.

@jannfis
Copy link
Member

jannfis commented Oct 26, 2020

@dewan-ahmed Looking at what's happening in test/e2e/fixture/fixture.go, I'd assume that authentication only works with hard-coded credentials also on the server side. That means your server must be set-up with an admin password of password - then RunCli() should work as expected.

@dewan-ahmed
Copy link
Contributor

Hi @jannfis that was the issue, thank you! Now the authentication error is gone.

@keithchong
Copy link
Contributor

Hi @alexmt, please have a look at my commit and my comment. I think the ui-tests should be 'independent' of the rest of the ArgoCD code.

@keithchong
Copy link
Contributor

keithchong commented Oct 28, 2020

Hi @alexmt, I created the PR for step 3. #4694. See PR for instructions on how to run the tests. When reviewing, take into account the points I made in one of my earlier comments in this issue,

Points to consider and possible follow-on enhancements

  • Need to customize it so you can specify any number of apps to be created. Right now it is just one app.
  • Add better error handling (edit: I added more to this in the PR. Stack traces are now more meaningful.)
  • Add better validation/verification after each step
  • Use mocha; launch a test suite of tests
  • the CLI will still need to be created to invoke the UI test or launch the test suites.
  • Add better error recovery. eg. how to return to the base state, say, no applications in the list, after one test is run but failed. and an app hasn't been deleted.

For the first point, if multiple apps are shown in the application list, there needs to be a way to correctly identify the Sync or Delete button in the tile of the desired app.

@dewan-ahmed
Copy link
Contributor

Further discussion on design of smoke test: https://argoproj.slack.com/archives/CEWCP8TV5/p1604506062335700

@dewan-ahmed
Copy link
Contributor

#4819 and #4820 issues have been created to break down the task regarding CLI part.

@dewan-ahmed
Copy link
Contributor

Note on argo-cd slack regarding smoke test scripts

cc: @alexmt

@dewan-ahmed
Copy link
Contributor

Hi @alexmt , I'm struggling to verify argocd app wait... from the CLI. While the app create.. and app sync.. are working (code here)[https://github.com/dewan-ahmed/argo-cd/tree/dewan-4820/test/smoke], the following piece of code is panic-ing

Running tool: /usr/local/bin/go test -timeout 30s github.com/argoproj/argo-cd/test/smoke -run ^TestWaitApp$

panic: test timed out after 30s

goroutine 19 [running]:
testing.(*M).startAlarm.func1()
/usr/local/Cellar/go/1.15.3/libexec/src/testing/testing.go:1618 +0xe5

func TestWaitApp(t *testing.T) {
	expectedBefore := "OutOfSync"
	// Create the guestbook app if not already created
	_, err := RunCmd("argocd", "app", "create", "guestbook", "--repo", "https://github.com/argoproj/argocd-example-apps.git", "--path", "guestbook", "--dest-server", "https://kubernetes.default.svc", "--dest-namespace", "default")
	errors.CheckError(err)
	time.Sleep(1 * time.Second)
	// Check that OutOfSync shows in the argocd app wait output
	outputBefore, err := RunCmd("argocd", "app", "wait", "guestbook")
	errors.CheckError(err)
	outputBeforeAsString := BytesToString(outputBefore)
	passBefore := OutputContains(outputBeforeAsString, expectedBefore)
	fmt.Println(passBefore)
	assert.Equal(t, true, passBefore)

	/* second block of code will go here that will sync the app and then expect "Synced" in the 'argocd app wait...' output */ 
}

@dewan-ahmed
Copy link
Contributor

Added an agenda item on contributor call today to discuss this @alexmt . Since we went over the time, this issue was not discussed. Hoping to discuss during one of the future calls.

@alexmt alexmt modified the milestones: v1.8, v1.9 Dec 14, 2020
keithchong added a commit to keithchong/argo-cd that referenced this issue Dec 17, 2020
alexmt pushed a commit that referenced this issue Dec 17, 2020
keithchong added a commit to keithchong/argo-cd that referenced this issue Dec 18, 2020
rbreeze pushed a commit that referenced this issue Jan 12, 2021
@jessesuen jessesuen modified the milestones: v1.9, v1.10 Feb 16, 2021
shubhamagarwal19 pushed a commit to shubhamagarwal19/argo-cd that referenced this issue Apr 15, 2021
@alexmt alexmt modified the milestones: v2.1, v2.2 Jul 2, 2021
alexmt pushed a commit that referenced this issue Jul 29, 2021
@alexmt alexmt removed this from the v2.2 milestone Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:test Test requests (e2e or unit) enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants