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
Test race condition? (unit test?) [message #175583] Mon, 10 October 2011 08:16 Go to previous message
Simon is currently offline  Simon
Messages: 29
Registered: February 2011
Karma:
Junior Member
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
[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 01:29:25 GMT 2024

Total time taken to generate the page: 0.05164 seconds