A testcase for a Queue like class.

A

Antoon Pardon

I'm writing some sort of replacement for the Queue module.
I'm calling the class I'm writing a tube. However I'm stuck
in how I should write some testcases.

The tube will have an open method, with as argument an
access parameter that will determine if the thread wants
to put things (write) on the queue or will get (read) things
from the queue (or both). Now what I want is that a thread that
opens the tube for read access will block until a thread opens
the same tube for write access.

The problem is how do I put such a requirement in a test case?
 
P

Paul Rubin

Antoon Pardon said:
The tube will have an open method, with as argument an
access parameter that will determine if the thread wants
to put things (write) on the queue or will get (read) things
from the queue (or both). Now what I want is that a thread that
opens the tube for read access will block until a thread opens
the same tube for write access.

The problem is how do I put such a requirement in a test case?

Just open the tube for reading in a separate thread, with something like:

global done, lock
done = False
t = tube.open(self, "r")
done = True

Then you can tell whether the open is blocked by checking the done
flag. The test fixture would then open the tube for writing, checking
the flag immediately before and after. Actually you will need some
synchronization to make sure there's no race condition between "open"
returning and the flag being set. I'm sure you can figure out how.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top