FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Test race condition? (unit test?)
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Test race condition? (unit test?) [message #175588 is a reply to message #175583] Mon, 10 October 2011 12:36 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 10/10/2011 4:16 AM, Simon wrote:
> Hi,
>
> I have written a very simple file based lock/unlock system.
> the way it works is as follows.
>
> process A looks for File 'X', if file 'X' does not exists it tries to
> creates an empty file, 'Xa', and locks it, it then creates file 'X' and
> deletes file 'Xa'.
>
> process B is also looking for File 'X', if file 'X' does not exists it
> tries to create 'Xa', on failure it waits for a seconds and tries to
> obtain the lock again. Once/if the lock is obtained, it looks for file
> 'X' again and either uses it or creates it.
>
> process C looks for file 'X', if file 'X' exists it will use it.
>
> I try to write as much unit tests as possible and, as this is an
> important process, I would like to test the process above.
>
> 1- Can you think of any way I could test the above? As far as I know you
> cannot start multiple threads in php, (even in a dev environment).
>
> 2- Is there a better way of getting a lock like I am doing above?
>
> Many thanks
>
> Simon

Race conditions are always difficult to duplicate and troubleshoot when
they occur. And although with some third party tools you could process
php scripts in different threads, you probably don't want to (locking
between threads is different than locking between processes). The way
to typically troubleshoot such problems is to run multiple copies of the
script/program with waits for input at critical places. Run the script
concurrently from multiple windows to emulate the system.

The real question here is - what is the problem you're trying to
resolve. Without knowing that, it's difficult to recommend if there is
a better way.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Anyoen actively on here?
Next Topic: .htaccess vs PHP header(location:)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 04:57:04 GMT 2024

Total time taken to generate the page: 0.03683 seconds