Thursday, 20 April 2023

How to pause between tests to do a common task, then resume for assert in tests

Currently I have a scenario where there is a resource intensive task occurring in each test. What I want to do is make this task execute after all tests have generated and pause between executions. Then finally assert a condition. For example currently I have the task (let's say foo) running. This is currently executed as:

foo(var):
  SendAPIrequest_to_store(val) #--->> this takes a long time

test_A():
  var = generated data
  foo(var)
  assert generated data present in server

test_B():
  var = generated value
  foo(var)
  assert generated data present in server

....

test_X():
  var = generated value
  foo(var)
  assert generated data present in server



This server can, let's say add multiple data at once - hence instead of running the whole task individually, I am looking for a way to achieve the following behaviour:

add_data(x):
  val = val + "," + x

foo(var):
  # this function will be run after all the test data has been added with all tests currently being suspended till generation
  SendAPIrequest_to_store(val) #----> this takes a long time
  # now we will continue the execution for the tests from where it was paused in sequence
  # so assert data for test_A then continue assertion for test_B and so-on



test_A():
  var = generated data
  add_data(var)
  PAUSE and move to the next test
  assert generated data present in server

test_B():
  var = generated value
  add_data(var)
  PAUSE and move to the next test
  assert generated data present in server

....

test_X():
  var = generated value
  add_data(var)
  PAUSE and move to the next test
  assert generated data present in server

Any help or pointers will be greatly appreciated. Thank you in advance



from How to pause between tests to do a common task, then resume for assert in tests

No comments:

Post a Comment