By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,587 Members | 1,667 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

A testcase for a Queue like class.

P: n/a
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?

--
Antoon Pardon
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Antoon Pardon <ap*****@forel.vub.ac.be> writes:
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.
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.