testing - How can I test race conditions created by multiple ajax requests to php? -


I am using PHP to create some objects in DB. Occasionally, if a user requests an object, while it is being made, then it can see partially created objects (main DB entry is present but all things object has not yet been included) . I have recently implemented a fix, where my code object is created entirely by adding a 'creation' flag only to DB entry.

How do I check this? I am using phpunit as two problems like I see that I need parallel threads to create and create at the same time, and I have to make sure that the time is right, so I actually have the running position (And not just get the object after it is made entirely after that). I want to see my test this way, but open to suggestions:

  1. Thread 1: Create an object
  2. Thread 2: Before the object is completely created Try to get (should work)

  • Itemprop = "text">

    Testing for the conditions of the race is already difficult in those languages ​​which are actually supporting threads - with PHP, it is also difficult in single-threaded context The poses must be triggered in parallel, to maintain the correct order of these requests so that the test does not fail randomly.

    I did once with the test, PHP session locking works correctly:

    In PHPUnit, I created a specially prepared php script firing curl_multi_query against three requests against the webserver , Which essentially only starts one session and then sleeps for a second.

    P> If the execution of three requests lasts longer than 2.5 seconds then the test is successful. (

    I think the requests will be answered in any (potentially random) order. I'm not sure that curl detail will guarantee to start the requests in a certain order. Additionally, I'm not sure that the web server will work on getting three requests almost instantly. I should admit that the only way to detect locking was successful, it has been successful in measuring the time.

    Especially I'm not sure that building an exam that will set two parallel requests to fire, the second failure as always, as you want, will be successful successfully. The only hope would be that one of the two requests will fail.


  • Comments