Skip to content

Commit

Permalink
Fix a data race in GraphDatabaseServiceTest
Browse files Browse the repository at this point in the history
The GraphDatabaseServiceTest.shouldLetDtectedDeadllocksDuringCommitBeThrownInTheirOriginalForm test created a transaction in a companion thread.
It then ended up closing this transaction from that other thread, which resulted in weird non-deterministic exceptions during KernelTransactionImplementation.close().
  • Loading branch information
chrisvest committed Mar 4, 2015
1 parent 4409178 commit 6856689
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Expand Up @@ -129,7 +129,7 @@ private void assertValidArguments( Object resource, Object tx )
{
if ( resource == null || tx == null )
{
throw new IllegalResourceException( "Null parameter" );
throw new IllegalResourceException( "Null parameter: resource = " + resource + ", tx = " + tx );
}
}

Expand Down
Expand Up @@ -19,16 +19,16 @@
*/
package org.neo4j.graphdb;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;

import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;

import org.neo4j.kernel.DeadlockDetectedException;
import org.neo4j.kernel.impl.MyRelTypes;
import org.neo4j.test.CleanupRule;
Expand Down Expand Up @@ -293,7 +293,9 @@ public void shouldLetDetectedDeadlocksDuringCommitBeThrownInTheirOriginalForm()
}
finally
{
t2Tx.close();
t2n2Wait.get();
t2.execute( close( t2Tx ) );
t2.close();
}
}

Expand Down Expand Up @@ -323,6 +325,19 @@ public Object doWork( Void state ) throws Exception
};
}

private WorkerCommand<Void, Void> close( final Transaction tx )
{
return new WorkerCommand<Void,Void>()
{
@Override
public Void doWork( Void state ) throws Exception
{
tx.close();
return null;
}
};
}

private Relationship createRelationship( Node node )
{
try ( Transaction tx = node.getGraphDatabase().beginTx() )
Expand Down

0 comments on commit 6856689

Please sign in to comment.