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

Support executing one test multiple times #1614

Closed
kkaarreell opened this issue Oct 19, 2022 · 13 comments
Closed

Support executing one test multiple times #1614

kkaarreell opened this issue Oct 19, 2022 · 13 comments
Labels
breakage Change will change current behaviour step | discover Stuff related to the discover step step | execute Stuff related to the execute step
Milestone

Comments

@kkaarreell
Copy link
Collaborator

kkaarreell commented Oct 19, 2022

When a test case is run multiple times in a test plan, the resulting junit will contain just a single <testcase> record with a consolidated log in <system-out> element.
Instead, separate <testcase> record should be created for each test case run.

The following warning should be added to the documentation as part of the fixing pull request:

Using cwd for storing test files is not a good idea, especially for multihost testing, use TMT_TEST_DATA instead.

@lukaszachy
Copy link
Collaborator

Could you paste reproducer please? I've tried

 /plan:
  execute:
    how: tmt
  discover:
    how: fmf
    test:
    - /test
    - /test
  provision:
    how: local

/test:
  test: echo

but resulting junit.xml contains two testcases (tried with 1.18.0)

@kkaarreell
Copy link
Collaborator Author

kkaarreell commented Oct 21, 2022

@lukaszachy
I am observing it in Packit CI on GitHub.
Plan is https://github.com/RedHat-SP-Security/keylime-tests/blob/main/plans/upstream-keylime-tests-github-ci.fmf
and the log is
https://artifacts.dev.testing-farm.io/87e413da-578a-47b9-bc06-a13ba2b0aace/
/functional/basic-attestation-on-localhost is the test run multiple times.

@lukaszachy
Copy link
Collaborator

Pardon my ignorance but where is the produced junit? https://artifacts.dev.testing-farm.io/7f36ff62-a883-4f2f-ba6b-215c840a47bb/work-rust-keylime-testsEeTL_a/ shows that 'report -h display' is run, not junit.

Either way, tmt has problem to create correct multiple results for same test. But for some reason display (and junit) report correct number as far as I can tell.

@kkaarreell
Copy link
Collaborator Author

kkaarreell commented Oct 21, 2022

I am sorry, I have accidentally pasted wrong link for logs.. fixing now.
There is results-junit.xml which is AFAIK junit from tmt post-processed by Testing Farm. I don't know if original junit is available. Of course, it is also possible that it is that post-processing introducing this issue.

@lukaszachy lukaszachy changed the title Having test case multiple times in a plan results in a single testcase record in junit results.yaml cannot store repeated test execution Oct 21, 2022
@lukaszachy
Copy link
Collaborator

I can't find dedicated issue for tmt's incomplete results.yaml so I'd use this one for it.
See https://artifacts.dev.testing-farm.io/87e413da-578a-47b9-bc06-a13ba2b0aace/work-upstream-keylime-tests-github-ciXsKbgX/plans/upstream-keylime-tests-github-ci/execute/results.yaml - unfortunately it's a dictionary.

We have to change that.

@lukaszachy
Copy link
Collaborator

This isn't problem for junit (and other report plugins). The issue is in what they are served (even though it is correct number of results in most cases it certainly isn't correct results)

@lukaszachy
Copy link
Collaborator

Modified reproducer:

/plan:
  execute:
    how: tmt
  discover:
    how: fmf
    test:
    - /test
    - /test
  provision:
    how: container

/test:
  test: |
    test -e this && exit 0 ;
    touch this && exit 1

This is produced junit.xml (from report -h junit):

<?xml version="1.0" ?>
<testsuites disabled="0" errors="0" failures="1" tests="2" time="0.0">
	<testsuite disabled="0" errors="0" failures="1" name="/plan" skipped="0" tests="2" time="0">
		<testcase name="/test">
			<failure type="failure" message="fail"/>
		</testcase>
		<testcase name="/test"/>
	</testsuite>
</testsuites>

But problem is when one reads results.yaml, only one results is there:

/test:
    result: pass
    log:
      - data/test/output.txt
    duration: 00:00:00

So if one regenerates report from saved rundir (tmt run --last report):

/plan
    report
        status: done
        summary: 1 test passed

@lukaszachy lukaszachy added step | execute Stuff related to the execute step breakage Change will change current behaviour labels Oct 21, 2022
@psss psss added this to the 1.22 milestone Jan 25, 2023
@psss psss changed the title results.yaml cannot store repeated test execution Support executing one test multiple times Jan 27, 2023
@psss psss added the step | discover Stuff related to the discover step label Jan 27, 2023
@psss
Copy link
Collaborator

psss commented Jan 27, 2023

Summary from the hacking session and multihost discussion:

  • Assign a unique identifier for each test execution during the discover phase
  • Use test name with a suffix to allow easy log investigation (tab completion in workdir)
  • Convert the tests.yaml and results.yaml files format from dict to a list of dictionaries

Example tests.yaml file created by the discover step:

- identifier: /tests/area/feature/001
  name: /tests/area/feature
  summary: This is a test for this area
  test: ./test.sh
  path: /default-0/tests/tests/area/feature
  id: af994876-1c68-49a7-90e8-c8d2b189189d
  ...

- identifier: /tests/area/feature/002
  name: /tests/area/feature
  summary: This is a test for this area
  test: ./test.sh
  path: /default-0/tests/tests/area/feature
  id: af994876-1c68-49a7-90e8-c8d2b189189d
  ...

- identifier: /tests/area/feature/003
  name: /tests/area/feature
  summary: This is a test for this area
  test: ./test.sh
  path: /default-0/tests/tests/area/feature
  id: af994876-1c68-49a7-90e8-c8d2b189189d
  ...

Example results.yaml file created by the execute step:

- identifier: /tests/area/feature/01
  name: /tests/area/feature
  result: pass
  duration: 00:00:00
  log:
    - data/test/output.txt

- identifier: /tests/area/feature/02
  name: /tests/area/feature
  result: pass
  duration: 00:00:00
  log:
    - data/test/output.txt

- identifier: /tests/area/feature/03
  name: /tests/area/feature
  result: pass
  duration: 00:00:00
  log:
    - data/test/output.txt

Not sure about the name of the new identifier key. It is an identifier, but id is already used for the core attribute. It is also a test-log-dir, or test-data-dir or something like test-case-run-id. Don't know. Any better ideas?

@happz
Copy link
Collaborator

happz commented Jan 27, 2023

results.yaml lacks the guest-the-test-ran-on info, e.g.

- identifier: /tests/area/feature/01
  name: /tests/area/feature
  result: pass
  duration: 00:00:00
  log:
    - data/test/output.txt
  guest:  # as an object? I like namespaces, guest_name and guest_role would look weird to me...
    name: foo
    role: client
    # Any more fields? `guest` with the IP/hostname?

Not sure about the name of the new identifier key. It is an identifier, but id is already used for the core attribute. It is also a test-log-dir, or test-data-dir or something like test-case-run-id. Don't know. Any better ideas?

Right, identifier does not look right to me, too. It's how the test instance is identified among its peers within the context of what, one phase? phase-id or step-id smell like they are id of a phase/step rather than the test within a phase... Focusing on the data directory nature of this key makes sense to me, data-dir wouldn't be bad, as it's sort of exactly this, but there might be other things we might derive from this id, so it's probably a wrong direction and "id" should be preferred. serial-number? :)

@kkaarreell
Copy link
Collaborator Author

Yes, serial-number wiki definition matches precisely.

happz added a commit that referenced this issue Feb 10, 2023
* drop `ResultData`, it's no longer needed and `Result` can handle all
  the work;
* add `guest` key as proposed in [1];
* add schema for validation of (custom) `results.yaml`;
* `execute` step saves `results.yaml` as a list of results rather than a
  mapping, to make allow one test being executed multiple times. See [2].

[1] #1614 (comment)
[2] #1614
happz added a commit that referenced this issue Feb 10, 2023
* drop `ResultData`, it's no longer needed and `Result` can handle all
  the work;
* add `guest` key as proposed in [1];
* add schema for validation of (custom) `results.yaml`;
* `execute` step saves `results.yaml` as a list of results rather than a
  mapping, to make allow one test being executed multiple times. See [2].

[1] #1614 (comment)
[2] #1614
happz added a commit that referenced this issue Feb 10, 2023
* drop `ResultData`, it's no longer needed and `Result` can handle all
  the work;
* add `guest` key as proposed in [1];
* add schema for validation of (custom) `results.yaml`;
* `execute` step saves `results.yaml` as a list of results rather than a
  mapping, to make allow one test being executed multiple times. See [2].

[1] #1614 (comment)
[2] #1614
happz added a commit that referenced this issue Feb 13, 2023
* drop `ResultData`, it's no longer needed and `Result` can handle all
  the work;
* add `guest` key as proposed in [1];
* add schema for validation of (custom) `results.yaml`;
* `execute` step saves `results.yaml` as a list of results rather than a
  mapping, to make allow one test being executed multiple times. See [2].

[1] #1614 (comment)
[2] #1614
@happz
Copy link
Collaborator

happz commented Feb 15, 2023

Submitted #1854 which turns tests.yaml into a list - this seems to be trivial enough for me to do, there are no serial-number or path changes involved. Those can be added on top of this change independently.

happz added a commit that referenced this issue Feb 20, 2023
* drop `ResultData`, it's no longer needed and `Result` can handle all
  the work;
* add `guest` key as proposed in [1];
* add schema for validation of (custom) `results.yaml`;
* `execute` step saves `results.yaml` as a list of results rather than a
  mapping, to make allow one test being executed multiple times. See [2].

[1] #1614 (comment)
[2] #1614
happz added a commit that referenced this issue Feb 20, 2023
* drop `ResultData`, it's no longer needed and `Result` can handle all
  the work;
* add `guest` key as proposed in [1];
* add schema for validation of (custom) `results.yaml`;
* `execute` step saves `results.yaml` as a list of results rather than a
  mapping, to make allow one test being executed multiple times. See [2].

[1] #1614 (comment)
[2] #1614
happz added a commit that referenced this issue Feb 21, 2023
* drop `ResultData`, it's no longer needed and `Result` can handle all
  the work;
* add `guest` key as proposed in [1];
* add schema for validation of (custom) `results.yaml`;
* `execute` step saves `results.yaml` as a list of results rather than a
  mapping, to make allow one test being executed multiple times. See [2].

[1] #1614 (comment)
[2] #1614
psss pushed a commit that referenced this issue Feb 21, 2023
* drop `ResultData`, it's no longer needed and `Result` can handle all
  the work;
* add `guest` key as proposed in [1];
* add schema for validation of (custom) `results.yaml`;
* `execute` step saves `results.yaml` as a list of results rather than a
  mapping, to make allow one test being executed multiple times. See [2].

[1] #1614 (comment)
[2] #1614
happz added a commit that referenced this issue Feb 22, 2023
* drop `ResultData`, it's no longer needed and `Result` can handle all
  the work;
* add `guest` key as proposed in [1];
* add schema for validation of (custom) `results.yaml` (the schema is
  not applied yet);
* `execute` step saves `results.yaml` as a list of results rather than a
  mapping, to make allow one test being executed multiple times. See [2].

[1] #1614 (comment)
[2] #1614
psss pushed a commit that referenced this issue Feb 22, 2023
* drop `ResultData`, it's no longer needed and `Result` can handle all
  the work;
* add `guest` key as proposed in [1];
* add schema for validation of (custom) `results.yaml` (the schema is
  not applied yet);
* `execute` step saves `results.yaml` as a list of results rather than a
  mapping, to make allow one test being executed multiple times. See [2].

[1] #1614 (comment)
[2] #1614
@happz
Copy link
Collaborator

happz commented Apr 2, 2023

I believe this issue can be closed now, as both results.yaml and tests.yaml support tests as a list rather than a dictionary.

@psss
Copy link
Collaborator

psss commented Apr 4, 2023

Agreed, but let's add at least a basic test coverage checking that: #1965

@psss psss closed this as completed Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breakage Change will change current behaviour step | discover Stuff related to the discover step step | execute Stuff related to the execute step
Projects
None yet
Development

No branches or pull requests

4 participants