From 0b5e5832c4e2de431b1042528f4928f201f4247c Mon Sep 17 00:00:00 2001 From: catbref Date: Fri, 14 Aug 2020 09:57:08 +0100 Subject: [PATCH] Added another repository deadlock test while investigating a deadlock case --- .../java/org/qortal/test/RepositoryTests.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/java/org/qortal/test/RepositoryTests.java b/src/test/java/org/qortal/test/RepositoryTests.java index c9532d27..7b20bbd9 100644 --- a/src/test/java/org/qortal/test/RepositoryTests.java +++ b/src/test/java/org/qortal/test/RepositoryTests.java @@ -95,6 +95,28 @@ public class RepositoryTests extends Common { } } + @Test + public void testUpdateReadDeadlock() throws DataException { + // Open connection 1 + try (final Repository repository1 = RepositoryManager.getRepository()) { + // Mint blocks so we have data (online account signatures) to work with + for (int i = 0; i < 10; ++i) + BlockUtils.mintBlock(repository1); + + // Perform database 'update', but don't commit at this stage + repository1.getBlockRepository().trimOldOnlineAccountsSignatures(System.currentTimeMillis()); + + // Open connection 2 + try (final Repository repository2 = RepositoryManager.getRepository()) { + // Perform database read on same blocks - this should not deadlock + repository2.getBlockRepository().getTimestampFromHeight(5); + } + + // Save updates - this should not deadlock + repository1.saveChanges(); + } + } + /** Check that the sub-query used to fetch highest block height is optimized by HSQLDB. */ @Test public void testBlockHeightSpeed() throws DataException, SQLException {