Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #3358

Test race condition? (unit test?)

From Simon <bad@example.com>
Newsgroups comp.lang.php
Subject Test race condition? (unit test?)
Date 2011-10-10 10:16 +0200
Message-ID <9ffnu3Fpb9U1@mid.individual.net> (permalink)

Show all headers | View raw


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

Back to comp.lang.php | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Test race condition? (unit test?) Simon <bad@example.com> - 2011-10-10 10:16 +0200
  Re: Test race condition? (unit test?) Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-10 08:36 -0400
    Re: Test race condition? (unit test?) Simon <bad@example.com> - 2011-10-10 15:48 +0200
      Re: Test race condition? (unit test?) The Natural Philosopher <tnp@invalid.invalid> - 2011-10-10 15:43 +0100
      Re: Test race condition? (unit test?) Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-10 13:42 -0400

csiph-web