# Testing concurrent accesses

**URL:** <https://www.ruby-forum.com/t/testing-concurrent-accesses/108746>\
**Category:** Rails\
**Created:** [July 6, 2007, 3:45pm UTC](https://www.ruby-forum.com/t/testing-concurrent-accesses/108746 "2007-07-06T15:45:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lionel\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@Lionel\_B](https://www.ruby-forum.com/u/Lionel_B)\
**Post date:** [July 6, 2007, 3:45pm UTC](https://www.ruby-forum.com/t/testing-concurrent-accesses/108746/1 "2007-07-06T15:45:37Z")

</div>

Hi,

I’ve recently come across a bug in one of my applications where  
destroying a model can occur while it’s locked in another place for  
processing. Just for the record: the destroy correctly aborts because of  
this but there are files removed by dependent models being destroyed to  
that can’t be restored when the rollback occurs (after\_destroy is not  
delayed until the actual commit…).

I know how I can solve this but I would like to create a test before  
(TDD/BDD are my friends…) and I don’t know how I can handle this in  
tests (reproducing a race condition isn’t especially easy).

Is there anyone on this list with experience to share on this particular  
subject?

Lionel

---

<div class="post-metadata">

**Author:** ![Lionel\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@Lionel\_B](https://www.ruby-forum.com/u/Lionel_B)\
**Post date:** [July 6, 2007, 3:55pm UTC](https://www.ruby-forum.com/t/testing-concurrent-accesses/108746/2 "2007-07-06T15:55:38Z")

</div>

You might find this article on the JMock site useful -  
[http://www.jmock.org/threads.html](http://www.jmock.org/threads.html)

They suggest trying to separate out the concurrency as a separate  
class and then write unit tests around the business logic while  
mocking out the concurrency.

## This approach has worked for me in the past.

James.

> **[James Mead](https://jamesmead.org/)**
>
> Ruby Developer, author of Mocha, and ex-Antarctic Hero.
