def test_hash_or_dimensions(self): dim1 = _gen_request(properties=_gen_properties( dimensions={u'foo': [u'a|c|b', u'xyz']})).task_slice( 0).properties.dimensions dim2 = _gen_request(properties=_gen_properties( dimensions={u'foo': [u'xyz', u'b|c|a']})).task_slice( 0).properties.dimensions self.assertEqual(task_queues.hash_dimensions(dim1), task_queues.hash_dimensions(dim2))
def new_task_to_run(request, try_number, task_slice_index): """Returns a fresh new TaskToRun for the task ready to be scheduled. Returns: Unsaved TaskToRun entity. """ assert 1 <= try_number <= 2, try_number assert 0 <= task_slice_index < 64, task_slice_index created = request.created_ts if try_number != 1 or task_slice_index: # When retrying, use the current time. created = utils.utcnow() # TODO(maruel): expiration_ts is based on request.created_ts but it could be # enqueued sooner or later. crbug.com/781021 offset = 0 if task_slice_index: for i in xrange(task_slice_index): offset += request.task_slice(i).expiration_secs exp = request.created_ts + datetime.timedelta( seconds=request.task_slice(task_slice_index).expiration_secs + offset) h = request.task_slice(task_slice_index).properties.dimensions qn = _gen_queue_number(task_queues.hash_dimensions(h), request.created_ts, request.priority) return TaskToRun(key=request_to_task_to_run_key(request, try_number, task_slice_index), created_ts=created, queue_number=qn, expiration_ts=exp)
def test_hash_dimensions(self): with self.assertRaises(AttributeError): task_queues.hash_dimensions('this is not json') # Assert it doesn't return 0. self.assertEqual(3649838548, task_queues.hash_dimensions({}))