Changesets · Branches · Tags · Compare
| Changeset | 6e1f74e501820f548ed449634464111aaa53365b9e7f55a8401105fa48617861 |
|---|---|
| Author | Jakub Blach <jakubblach@gmail.com> · 2025-07-07 16:01 +02:00 |
| Committer | Jakub Blach <jakubblach@gmail.com> · 2025-07-08 14:27 +02:00 |
| Parents | 554dc5ae3b37 |
2 files changed
deleted extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/continue/process/ContinueProcessHandlerTest.kt +0 −49
| @@ -1,49 +0,0 @@ | ||
| 1 | -package com.github.continuedev.continueintellijextension.`continue`.process | |
| 2 | - | |
| 3 | -import kotlinx.coroutines.Dispatchers | |
| 4 | -import kotlinx.coroutines.joinAll | |
| 5 | -import kotlinx.coroutines.launch | |
| 6 | -import kotlinx.coroutines.test.runTest | |
| 7 | -import org.junit.jupiter.api.Assertions.assertTrue | |
| 8 | -import org.junit.jupiter.api.RepeatedTest | |
| 9 | -import java.io.InputStream | |
| 10 | -import java.io.OutputStream | |
| 11 | - | |
| 12 | -class ContinueProcessHandlerTest { | |
| 13 | - | |
| 14 | - @RepeatedTest(5) | |
| 15 | - fun `test concurrent writes with queue`() = runTest { | |
| 16 | - val process = StringContinueProcess() | |
| 17 | - val handler = ContinueProcessHandler(this, process) {} | |
| 18 | - | |
| 19 | - (0..100).map { i -> launch(Dispatchers.Default) { handler.write("message number $i") } } | |
| 20 | - .joinAll() | |
| 21 | - | |
| 22 | - handler.close() | |
| 23 | - | |
| 24 | - // assert all message lines are present (order not important) | |
| 25 | - val lines = process.string.split("\r\n").filter { it.isNotBlank() } | |
| 26 | - for (i in 0..100) | |
| 27 | - assertTrue(lines.contains("message number $i")) | |
| 28 | - | |
| 29 | - // note: this test will fail if the handler writes messages directly to the output stream | |
| 30 | - // this problem can be easily reproduced by removing the channel<string> from the handler code | |
| 31 | - } | |
| 32 | - | |
| 33 | - class StringContinueProcess : ContinueProcess { | |
| 34 | - val string = StringBuilder() | |
| 35 | - override val input: InputStream = InputStream.nullInputStream() | |
| 36 | - override val output: OutputStream = object : OutputStream() { | |
| 37 | - override fun write(b: Int) { | |
| 38 | - string.append(b.toChar()) | |
| 39 | - } | |
| 40 | - | |
| 41 | - override fun write(b: ByteArray, off: Int, len: Int) { | |
| 42 | - string.append(String(b, off, len)) | |
| 43 | - } | |
| 44 | - } | |
| 45 | - | |
| 46 | - override fun close() { | |
| 47 | - } | |
| 48 | - } | |
| 49 | -} | |
| No newline at the end of the file |
added extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/unit/ContinueProcessHandlerTest.kt +51 −0
| @@ -0,0 +1,51 @@ | ||
| 1 | +package com.github.continuedev.continueintellijextension.unit | |
| 2 | + | |
| 3 | +import com.github.continuedev.continueintellijextension.`continue`.process.ContinueProcess | |
| 4 | +import com.github.continuedev.continueintellijextension.`continue`.process.ContinueProcessHandler | |
| 5 | +import kotlinx.coroutines.Dispatchers | |
| 6 | +import kotlinx.coroutines.joinAll | |
| 7 | +import kotlinx.coroutines.launch | |
| 8 | +import kotlinx.coroutines.test.runTest | |
| 9 | +import org.junit.jupiter.api.Assertions | |
| 10 | +import org.junit.jupiter.api.RepeatedTest | |
| 11 | +import java.io.InputStream | |
| 12 | +import java.io.OutputStream | |
| 13 | + | |
| 14 | +class ContinueProcessHandlerTest { | |
| 15 | + | |
| 16 | + @RepeatedTest(5) | |
| 17 | + fun `test concurrent writes with queue`() = runTest { | |
| 18 | + val process = StringContinueProcess() | |
| 19 | + val handler = ContinueProcessHandler(this, process) {} | |
| 20 | + | |
| 21 | + (0..100).map { i -> launch(Dispatchers.Default) { handler.write("message number $i") } } | |
| 22 | + .joinAll() | |
| 23 | + | |
| 24 | + handler.close() | |
| 25 | + | |
| 26 | + // assert all message lines are present (order not important) | |
| 27 | + val lines = process.string.split("\r\n").filter { it.isNotBlank() } | |
| 28 | + for (i in 0..100) | |
| 29 | + Assertions.assertTrue(lines.contains("message number $i")) | |
| 30 | + | |
| 31 | + // note: this test will fail if the handler writes messages directly to the output stream | |
| 32 | + // this problem can be easily reproduced by removing the channel<string> from the handler code | |
| 33 | + } | |
| 34 | + | |
| 35 | + class StringContinueProcess : ContinueProcess { | |
| 36 | + val string = StringBuilder() | |
| 37 | + override val input: InputStream = InputStream.nullInputStream() | |
| 38 | + override val output: OutputStream = object : OutputStream() { | |
| 39 | + override fun write(b: Int) { | |
| 40 | + string.append(b.toChar()) | |
| 41 | + } | |
| 42 | + | |
| 43 | + override fun write(b: ByteArray, off: Int, len: Int) { | |
| 44 | + string.append(String(b, off, len)) | |
| 45 | + } | |
| 46 | + } | |
| 47 | + | |
| 48 | + override fun close() { | |
| 49 | + } | |
| 50 | + } | |
| 51 | +} | |
| No newline at the end of the file |