Skip to content

Commit

Permalink
fix: fix recursive game server assignment (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc authored Jun 18, 2020
1 parent 9cc7368 commit ab08f22
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/games/services/game-launcher.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { GamesGateway } from '../gateways/games.gateway';

const mockGame = {
id: 'FAKE_GAME_ID',
_id: 'FAKE_GAME_ID',
number: 2,
state: 'launching',
gameServer: null,
Expand All @@ -21,6 +22,7 @@ class GamesServiceStub {

const mockGameServer = {
id: 'FAKE_GAME_SERVER_ID',
_id: 'FAKE_GAME_SERVER_ID',
name: 'FAKE_GAME_SERVER',
mumbleChannelName: 'FAKE_SERVER_MUMBLE_CHANNEL_NAME',
game: undefined,
Expand Down Expand Up @@ -89,13 +91,13 @@ describe('GameLauncherService', () => {

it('should take the game server', async () => {
await service.launch('FAKE_GAME_ID');
expect(mockGameServer.game.id).toEqual(mockGame.id);
expect(mockGameServer.game).toEqual(mockGame.id);
});

it('should configure the game server', async () => {
const spy = jest.spyOn(serverConfiguratorService, 'configureServer');
const ret = await service.launch('FAKE_GAME_ID');
expect(spy).toHaveBeenCalledWith(jasmine.objectContaining({ id: mockGameServer.id }), jasmine.objectContaining({ id: mockGame.id }));
expect(spy).toHaveBeenCalledWith(expect.objectContaining({ id: mockGameServer.id }), expect.objectContaining({ id: mockGame.id }));
expect(ret.connectString).toEqual('FAKE_CONNECT_STRING');
expect(ret.stvConnectString).toEqual('FAKE_STV_CONNECT_STRING');
});
Expand Down
4 changes: 2 additions & 2 deletions src/games/services/game-launcher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export class GameLauncherService {
this.logger.verbose(`using server ${gameServer.name} for game #${game.number}`);

// step 1: obtain a free server
gameServer.game = game;
game.gameServer = gameServer;
gameServer.game = game._id;
game.gameServer = gameServer._id;
await game.save();
this.gamesGateway.emitGameUpdated(game);

Expand Down

0 comments on commit ab08f22

Please sign in to comment.