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

Add game testing. #2050

Merged
merged 21 commits into from
Jun 19, 2018
Merged

Add game testing. #2050

merged 21 commits into from
Jun 19, 2018

Conversation

o01eg
Copy link
Contributor

@o01eg o01eg commented Mar 12, 2018

This PR adds tests for the game itself.
Test acts as a host for the game server. It starts singleplayer game, make a turns and check if server and AIs acts correctly and within time limits.
Test accepts environment variables FO_TEST_GAME_AIS to manage number of AI players, FO_TEST_GAME_TURNS to manage numbers of turns to make, and FO_TEST_GAME_SAVE to save game after each turn.
Test will stop when test player will be eliminated or someone wins the game.

Other changes:

  • Added Process::Terminate method to ensure server was stopped correctly.
  • ClientApp::VerifyCheckSum returns bool instead void.
  • Add server flag --testing to output AI logs to stdout.

@o01eg o01eg force-pushed the test-server branch 5 times, most recently from 6f03327 to a13b0ae Compare March 14, 2018 10:21
@geoffthemedio geoffthemedio added category:feature The Issue/PR describes or implements a new game feature. component:infrastructure The Issue/PR deals with development aiding infrastructure like CI, distribution or helper tools. labels Mar 14, 2018
}
to_process = true;
} else {
if(to_process) {
Copy link
Member

Choose a reason for hiding this comment

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

Space between ( and if

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@o01eg
Copy link
Contributor Author

o01eg commented Mar 15, 2018

Rebased. Refactored and set time limits on game starting and turn processing.

@o01eg
Copy link
Contributor Author

o01eg commented Mar 24, 2018

Rebased. Added environment variables TEST_GAME_AIS to manage number of AI players and TEST_GAME_TURNS to manage numbers of turns to make.

@o01eg
Copy link
Contributor Author

o01eg commented Apr 10, 2018

Rebased. Implement testing saves. Add options TEST_GAME_SAVE to manage if saves will be applied (default true).

@o01eg
Copy link
Contributor Author

o01eg commented May 3, 2018

Rebased. Tested against new docker image.

@@ -1186,6 +1186,9 @@ Start server in hostless mode. Server accepts players in the multiplayer lobby,
OPTIONS_DB_SKIP_CHECKSUM
Skip comparing the resource directory checksums. This allows faster startup when client and server are on the same machine, using the same resource directory.

OPTIONS_DB_TESTING
Start server in testing mode. AI playing will be output log to colnsole instead file (Linux only).
Copy link
Member

@geoffthemedio geoffthemedio May 5, 2018

Choose a reason for hiding this comment

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

colnsole
rewrite second sentence

Not clear if this option is Linux-only, or the to-consolve vs. to-file part is Linux-only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Option is no-op in other than Linux OS.

Copy link
Member

Choose a reason for hiding this comment

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

Put the "Linux only" at the start.

And perhaps don't even add it as an option in those cases...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the option to macro condition for FREEORION_LINUX.

@@ -260,6 +260,14 @@ void ServerApp::CreateAIClients(const std::vector<PlayerSetupData>& player_setup
args.push_back(GetOptionsDB().Get<std::string>("log-level"));
}

if (GetOptionsDB().Get<bool>("testing")) {
#ifdef FREEORION_LINUX
// Dirty hack to output log to console.
Copy link
Member

@geoffthemedio geoffthemedio May 5, 2018

Choose a reason for hiding this comment

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

why not use the standard log 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.

I'm not sure if it possible to get them from Travis CI to get detailed information about possible errors.

Copy link
Member

Choose a reason for hiding this comment

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

Running the tests isn't possible on AppVeyor as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It possible but logs will be output to files.

#include <boost/format.hpp>

ClientAppFixture::ClientAppFixture()
:m_game_started(false)
Copy link
Member

Choose a reason for hiding this comment

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

: to previous line, with space between it and )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

// Dirty hack to output log to console.
InitLoggingSystem("/proc/self/fd/1", "Test");
#else
InitLoggingSystem((GetUserDataDir() / "test.log").string(), "Test");
Copy link
Member

Choose a reason for hiding this comment

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

why not use standard log file location?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GetUserDataDir() is a standard folder for logs. test.log is used instead freeorion.log to distinguish unit test from human client.

}

int ClientAppFixture::EffectsProcessingThreads() const
{ return 1; }
Copy link
Member

Choose a reason for hiding this comment

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

Why not use standard option for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It requires unittest to have a fully initialized OptionsDB.

{ return m_networking->ConnectToLocalHostServer(); }

void ClientAppFixture::HostSPGame(unsigned int num_AIs) {
std::vector<std::pair<std::string, std::string>> game_rules = GetGameRules().GetRulesAsStrings();
Copy link
Member

Choose a reason for hiding this comment

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

prefer auto ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@o01eg
Copy link
Contributor Author

o01eg commented Jun 19, 2018

Rebased.

@geoffthemedio geoffthemedio merged commit ed13d4b into freeorion:master Jun 19, 2018
@geoffthemedio geoffthemedio added the status:merged All relevant commits of this PR were merged into the master development branch. label Jun 19, 2018
@o01eg
Copy link
Contributor Author

o01eg commented Jun 19, 2018

What if merge it into 0.4.8 branch too so release will be tested too?

@geoffthemedio
Copy link
Member

geoffthemedio commented Jun 19, 2018

no. adding new / potentially problematic stuff immediately before release not appropriate.

@o01eg o01eg deleted the test-server branch June 19, 2018 08:52
@Vezzra
Copy link
Member

Vezzra commented Jun 24, 2018

Considering the amount of changes to the codebase, this isn't a purely "infrastructure" PR anyway.

I'm going to add "component:internal" and a proper milestone (post release).

@Vezzra Vezzra added this to the post 0.4.8 milestone Jun 24, 2018
@Vezzra Vezzra added the component:internal The Issue/PR deals with any project component that has no explicit `component` label. label Jun 24, 2018
@Vezzra Vezzra modified the milestones: Next Release, v0.4.9 Sep 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:feature The Issue/PR describes or implements a new game feature. component:infrastructure The Issue/PR deals with development aiding infrastructure like CI, distribution or helper tools. component:internal The Issue/PR deals with any project component that has no explicit `component` label. status:merged All relevant commits of this PR were merged into the master development branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants