Skip to content

Commit

Permalink
tests to test multiple lanes
Browse files Browse the repository at this point in the history
  • Loading branch information
realtux committed Apr 14, 2017
1 parent 21784a2 commit d49db64
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,116 @@ def test034_queue_empty(self):
self.assertEqual(res.status_code, 200)
self.assertEqual(len(json['main']), 0)

def test040_queues_fill(self):
for i in range(0, 30):
res = requests.post(self.base_url + '/schedule', \
json={'lane': 'lane1', 'priority': random.randint(0, 125), 'message': 'job #' + str(i)})
json = res.json()
self.assertEqual(res.status_code, 200)
self.assertEqual(json['status'], 'ok')
self.assertEqual(json['code'], 0)
for i in range(0, 50):
res = requests.post(self.base_url + '/schedule', \
json={'lane': 'lane2', 'priority': random.randint(0, 125), 'message': 'job #' + str(i)})
json = res.json()
self.assertEqual(res.status_code, 200)
self.assertEqual(json['status'], 'ok')
self.assertEqual(json['code'], 0)
for i in range(0, 70):
res = requests.post(self.base_url + '/schedule', \
json={'lane': 'lane3', 'priority': random.randint(0, 125), 'message': 'job #' + str(i)})
json = res.json()
self.assertEqual(res.status_code, 200)
self.assertEqual(json['status'], 'ok')
self.assertEqual(json['code'], 0)

def test041_queues_not_empty(self):
res = requests.get(self.base_url + '/jobs')
json = res.json()
self.assertEqual(res.status_code, 200)
self.assertEqual(len(json['lane1']), 30)
self.assertEqual(len(json['lane2']), 50)
self.assertEqual(len(json['lane3']), 70)

def test042_queues_properly_ordered(self):
res = requests.get(self.base_url + '/jobs')
json = res.json()
previous_priority = -1
previous_date = ''
for job in json['lane1']:
self.assertLessEqual(previous_priority, job['priority'])
if previous_priority == job['priority']:
self.assertLessEqual(previous_date, job['timestamp'])
previous_priority = job['priority']
previous_date = job['timestamp']
res = requests.get(self.base_url + '/jobs')
json = res.json()
previous_priority = -1
previous_date = ''
for job in json['lane2']:
self.assertLessEqual(previous_priority, job['priority'])
if previous_priority == job['priority']:
self.assertLessEqual(previous_date, job['timestamp'])
previous_priority = job['priority']
previous_date = job['timestamp']
res = requests.get(self.base_url + '/jobs')
json = res.json()
previous_priority = -1
previous_date = ''
for job in json['lane3']:
self.assertLessEqual(previous_priority, job['priority'])
if previous_priority == job['priority']:
self.assertLessEqual(previous_date, job['timestamp'])
previous_priority = job['priority']
previous_date = job['timestamp']

def test043_queue1_drains(self):
for i in range(0, 30):
res = requests.post(self.base_url + '/receive_noblock', \
json={'lane': 'lane1'})
json = res.json()
self.assertEqual(res.status_code, 200)
self.assertEqual(json['message'].startswith('job #'), True)

def test044_queue1_empty_queue23_full(self):
res = requests.get(self.base_url + '/jobs')
json = res.json()
self.assertEqual(res.status_code, 200)
self.assertEqual(len(json['lane1']), 0)
self.assertEqual(len(json['lane2']), 50)
self.assertEqual(len(json['lane3']), 70)

def test045_queue2_drains(self):
for i in range(0, 50):
res = requests.post(self.base_url + '/receive_noblock', \
json={'lane': 'lane2'})
json = res.json()
self.assertEqual(res.status_code, 200)
self.assertEqual(json['message'].startswith('job #'), True)

def test046_queue12_empty_queue3_full(self):
res = requests.get(self.base_url + '/jobs')
json = res.json()
self.assertEqual(res.status_code, 200)
self.assertEqual(len(json['lane1']), 0)
self.assertEqual(len(json['lane2']), 0)
self.assertEqual(len(json['lane3']), 70)

def test047_queue3_drains(self):
for i in range(0, 70):
res = requests.post(self.base_url + '/receive_noblock', \
json={'lane': 'lane3'})
json = res.json()
self.assertEqual(res.status_code, 200)
self.assertEqual(json['message'].startswith('job #'), True)

def test048_queue123_empty(self):
res = requests.get(self.base_url + '/jobs')
json = res.json()
self.assertEqual(res.status_code, 200)
self.assertEqual(len(json['lane1']), 0)
self.assertEqual(len(json['lane2']), 0)
self.assertEqual(len(json['lane3']), 0)

suite = unittest.TestLoader().loadTestsFromTestCase(TestDispenserd)

Expand Down

0 comments on commit d49db64

Please sign in to comment.