Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
More tests for worker manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
OlafSzmidt committed Sep 4, 2017
1 parent ded992f commit f4441b3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions aimmo-game-creator/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
tests_require=[
'httmock',
'mock',
],
test_suite='tests',
zip_safe=False,
Expand Down
46 changes: 46 additions & 0 deletions aimmo-game-creator/tests/test_worker_manager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from __future__ import absolute_import

import cPickle as pickle
import unittest

from json import dumps, loads

from httmock import HTTMock
import mock

from worker_manager import WorkerManager
from worker_manager import LocalWorkerManager


class ConcreteWorkerManager(WorkerManager):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -93,3 +98,44 @@ def test_added_workers_given_correct_url(self):
'http://test/{}/'.format(i)
)
self.assertEqual(self.worker_manager.added_workers[str(i)]['name'], 'Game %s' % i)

class TestLocalWorkerManager(unittest.TestCase):

def test_create_worker(self):
with mock.patch('subprocess.Popen') as mocked_popen:
localWorkerManager = LocalWorkerManager("")

game_id = 1
game_data = {
"test" : "test"
}

localWorkerManager.create_worker(game_id, game_data)
call_args = mocked_popen.call_args

argument_dictionary = call_args[1]
self.assertTrue("aimmo-game" in argument_dictionary["cwd"])
self.assertEqual(argument_dictionary["env"]["test"], "test")

def test_remove_worker(self):
self.killed = False
class KillableWorker():
def __init__(self, binder):
self.binder = binder
self.binder.killed = False

def kill(self):
self.binder.killed = True

localWorkerManger = LocalWorkerManager("")
localWorkerManger.workers = {
1 : KillableWorker(self)
}

self.assertFalse(self.killed)
self.assertTrue(1 in localWorkerManger.workers)

localWorkerManger.remove_worker(1)

self.assertTrue(self.killed)
self.assertTrue(1 not in localWorkerManger.workers)
9 changes: 4 additions & 5 deletions aimmo-game-worker/tests/simulation/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def test_repr(self):
self.assertTrue("Location(1, 2)" == str(dummy_location))







def test_not_equal(self):
dummy_location_1 = Location(1, 1)
dummy_location_2 = Location(2, 2)
self.assertTrue(dummy_location_1 != dummy_location_2)

0 comments on commit f4441b3

Please sign in to comment.