Skip to content

Your first integration test#3

Open
SlamBamActionman wants to merge 9 commits into
masterfrom
your-first-integration-test
Open

Your first integration test#3
SlamBamActionman wants to merge 9 commits into
masterfrom
your-first-integration-test

Conversation

@SlamBamActionman

Copy link
Copy Markdown
Owner

Review PR for Tayrtahn

@Tayrtahn Tayrtahn left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is looking good! There's definitely a bunch of stuff I want to add eventually, but this is a great start for getting some documentation released!

Comment thread src/en/ss14-by-example/your-first-integration-test.md Outdated
It can catch unintended behavior, bugs and even rare game-crashing errors when used properly!
This is achieved through **integration tests**, which basically run short simulations of the game and makes sure ingame values match what the test expects.

An example would be changing a Cargo order to cost less.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Mention the problem here and how it goes unnoticed, giving us reason to want a test

If you have an integration test that compares order costs to sell values, you'll be able to automatically catch if this change would result in an infinite money loop!

Integration tests are ran on all pull requests submitted to the SS14 repository and all tests must pass for a PR to be mergeable.
You can also run tests locally in your IDE (useful if you fail a specific test when submitting a PR).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should explain how - probably just linking to online guides for popular IDEs.

Comment thread src/en/ss14-by-example/your-first-integration-test.md Outdated
Comment thread src/en/ss14-by-example/your-first-integration-test.md Outdated
Comment thread src/en/ss14-by-example/your-first-integration-test.md
Comment thread src/en/ss14-by-example/your-first-integration-test.md Outdated
Comment thread src/en/ss14-by-example/your-first-integration-test.md Outdated
For tests specifically it allows for client-servers to be reused for multiple tests and for tests to be run in parallel, instead of constantly starting and shutting down such systems.

It's unlikely you will access `PoolManager` yourself, but a key property that all integration tests make use of is the `TestPair` class.
`TestPair` gives access to the Client and Server instances and therefore the ability to set CVars, resolve manager/system dependencies and map management.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Possibly mention the threading behavior of tests here, with the test thread orchestrating the actions of the client and server threads.

@Tayrtahn

Copy link
Copy Markdown

Oh! It would be good to add a section about cleanup and recycling. By default, tests are assumed to have returned everything to (approximately) the initial state when they finish. A lot of this is done automatically though (anything parented to the test map is deleted when the map is deleted, GameTest tracks and deletes stuff automatically), so it might not be obvious that it needs to be done. If a test spawns any entities in nullspace and doesn't delete them, they will leak into the next test run using that test pair (and any future tests on that pair until it is restarted). If possible, tests should clean up after themselves. If that's not really viable (ex: the gamerule tests have a lot of side effects that would be hard to keep track of, like spawning the nukie station, centcom, etc.), the test's pair config should have the Dirty flag set.

[Test]
public async Task HugTest()
{
var urist = await SpawnTarget("MobHuman");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't want to make the example too complicated, but we probably should be using PR-worthy example code, and if someone submitted a PR with this, I'd tell them to move this to a private static readonly EntProtoId for validation.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Totally valid

### Clean-up & Recycling

To make integration tests run fast and efficiently, the testing system is set up to save time by reusing servers, clients and entity systems across multiple tests.
Much of this is handled automatically under the hood. `GameTest` deletes the test map and any entities in it when a test has finished, but there may be instances where you will have to clean up manually.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The test map stuff is handled in TestPair, so this works outside of GameTest too.

};
```

Luckily, our test is simple enough that letting `GameTest` handle the map deletion and clean-up automatically should be sufficient.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We're not using GameTest in our example, so

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fair, I forgot InteractionTest doesn't inherit GameTest. Would would it work for this example?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I.e. marking it Dirty

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No need to use Dirty, TestPair will clean up the test map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants