How can i execute 2 testcases in paralel in the same exact time?

Hi,

I have a query about execution 2 testcases in paralel in the exact time.

I need to send the same message into different hosts with the same exact time.

Do we have such ability in robot Framework doing this?

Thanks

Best Regarads,

Joe

Hi Joe,

Welcome to the Robot Framework Community,

What I’m not clear about is do you actually need to run the same test twice or do you just need to send the result twice?

if you ran the test once and the result got sent to both reporting systems would this meet your needs?

The reason I ask is what are the implications if you run the test twice and it fails in one of those runs, so the two reporting systems have different results for the “same” test, I expect this would not be desirable.

Robot framework has several methods of reporting results to different reporting systems, so let us know which system you are using and we can try to point you in the right direction.

I just realised that I may have miss understood you question and you want to send the same request to two different application instances at the same time, presumably to compare the results. If that’s the case, please let us know which library your using, as the approach for doing that will vary by library.

Dave.

Hi Dave,

Actually I have python’s script to generate the message and sending it to 1 application only.

This script requires to import (socket, time, thread, etc). It works fine.

Now I need to send this messages to the others application, but it needs to be sent in the same time.

I read pabot is only for executing paralel execution in sequence/in order/split, but I need to execute it once for sending a message to both application, can we do that?

FYI, Im using ride-framework.

Thanks

Best Regards,

Joe

Hi Joe,

Dave already raised the key questions. If you really want two separate, independent test cases—as the title suggests—that would, in parallel, send the same message to two different systems, then in principle this is possible with Pabot. However, since Pabot’s processes do not actually communicate with each other, implementing this reliably would be difficult, and comparing the results between two test cases would not be possible. The easiest way to implement this would likely be by modifying your script directly in Python.

So could you elaborate a bit more on your use case? Do you truly need two separate test cases, or would a single test case that performs two sends in parallel and, for example, compares the results be sufficient? Also, how strict is the simultaneity requirement—are we talking milliseconds, microseconds, nanoseconds, or even picoseconds?

Regards,

Joonas

Hi Joonas,

I’d rather have two separate testcases and can be delivered to different test system in the same time, let’s say in miliseconds. it would be differenciated in Hostname.

What i’m concern is about the timestamp, if we could have an option to put a defined timestamp (nearly in the future) to send them both in paralel. When timestamp is reached, robot will execute these 2 testcases immediatelly.

To modify the scripts, yes, I will try to modify it.

Thanks

Best Regards,

Joe

Indeed, sending two messages to two different systems at exactly the same moment is practically impossible due to varying transmission delays and similar factors. However, if you use Python, you can achieve very good precision:

from multiprocessing import Process, Barrier
import requests

def send(url, barrier):
    barrier.wait()
    requests.post(url, json={“msg”: “hello”})

barrier = Barrier(2)
p1 = Process(target=send, args=("https://system-a.example/api", barrier))
p2 = Process(target=send, args=("https://system-b.example/api", barrier))

p1.start()
p2.start()

p1.join()
p2.join()

Pabot is not really intended for this kind of use case. Initializing a test case in Pabot always takes more or less time depending on the case, whereas in Python you can truly give both messages the “go” signal at the same moment.

Of cource, you could start two test cases and then wait spesific timestamps to occur but without any sleeps it is very CPU heavy and with sleeps it is not that accurate.

1 Like

Hi Joona,

Its helpfull, I will adapt my testcases with this python’s script.

Thank you for your feedback.

Best Regards,

Joe

Hi Joe,

I just caught up with the conversation,

Actually there is an easy way to get the tests to run at the same time by borrowing a performance testing concept of a rendezvous point, we can create a simple rendezvous point by defining a point in time to run, i.e. if you define the rendezvous point as every 5th minute or 300th second, then using Built-in’s Get Time with the epoch option you have the current time in seconds, apply modulo 300 to this and use the resulting value as the number of seconds to sleep. then both tests will exit the sleep at the same time (well in the same second, but you could use milliseconds if you need it more accurate)

It would look something like this:

${now} = 	Get Time 	epoch
${secs} = 	Evaluate 	${now} % 300
Sleep 	${secs}

You could wrap that as a keyword with the modulo value as an argument if you like.

I would also suggest as Joonas did, making the calls two separate tests and using pabot.

if that really doesn’t work for you, some other possibilities are:

  • Using AsyncLibrary to run the keyword calls in parallel and then get the values back after they finish running, though this is also likely to have a ms or 2 offset between the first and second calls

  • You mentioned you are making the calls as socket calls from python code, so if your comfortable coding in python you could modify your python function to take both hosts you want to target and use python to make the calls in separate threads or processes

There’s probably other options too, robot framework is quite flexible, it’s really a matter of determining which approach is best for your test case and the skill set of your test team to maintain.

Dave.

1 Like