From f9777d29f4e2c645ccb7d99af4edfe0ef3bcaed5 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 21 Jun 2019 05:41:49 +0100 Subject: [PATCH] get existing tests to pass --- .../com/muwire/core/download/DownloadSession.groovy | 3 ++- .../muwire/core/download/DownloadSessionTest.groovy | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/download/DownloadSession.groovy b/core/src/main/groovy/com/muwire/core/download/DownloadSession.groovy index d476829a..678b7e09 100644 --- a/core/src/main/groovy/com/muwire/core/download/DownloadSession.groovy +++ b/core/src/main/groovy/com/muwire/core/download/DownloadSession.groovy @@ -88,7 +88,8 @@ class DownloadSession { os.write("X-Persona: $meB64\r\n\r\n".getBytes(StandardCharsets.US_ASCII)) os.flush() String codeString = readTillRN(is) - codeString = codeString.substring(codeString.indexOf(' ')) + int space = codeString.indexOf(' ') + codeString = codeString.substring(0, space) int code = Integer.parseInt(codeString.trim()) diff --git a/core/src/test/groovy/com/muwire/core/download/DownloadSessionTest.groovy b/core/src/test/groovy/com/muwire/core/download/DownloadSessionTest.groovy index 9480658b..ccead90e 100644 --- a/core/src/test/groovy/com/muwire/core/download/DownloadSessionTest.groovy +++ b/core/src/test/groovy/com/muwire/core/download/DownloadSessionTest.groovy @@ -9,6 +9,7 @@ import com.muwire.core.files.FileHasher import static com.muwire.core.util.DataUtil.readTillRN import net.i2p.data.Base64 +import net.i2p.util.ConcurrentHashSet class DownloadSessionTest { @@ -24,6 +25,9 @@ class DownloadSessionTest { private InputStream fromDownloader, fromUploader private OutputStream toDownloader, toUploader + private volatile boolean performed + private Set available = new ConcurrentHashSet<>() + private void initSession(int size, def claimedPieces = []) { Random r = new Random() byte [] content = new byte[size] @@ -56,8 +60,8 @@ class DownloadSessionTest { toUploader = new PipedOutputStream(fromDownloader) endpoint = new Endpoint(null, fromUploader, toUploader, null) - session = new DownloadSession("",pieces, infoHash, endpoint, target, pieceSize, size) - downloadThread = new Thread( { session.request() } as Runnable) + session = new DownloadSession("",pieces, infoHash, endpoint, target, pieceSize, size, available) + downloadThread = new Thread( { performed = session.request() } as Runnable) downloadThread.setDaemon(true) downloadThread.start() } @@ -87,6 +91,8 @@ class DownloadSessionTest { assert pieces.isComplete() assert target.bytes == source.bytes + assert performed + assert available.isEmpty() } @Test