From e969fc961fcf96244c33847f29146facd92ba0cc Mon Sep 17 00:00:00 2001 From: tiagohm Date: Thu, 18 Jul 2024 23:25:22 -0300 Subject: [PATCH] [api]: Fix CommandLine timeout --- .../src/test/kotlin/LibAstrometryNetTest.kt | 6 +++--- .../nebulosa/common/exec/CommandLine.kt | 9 ++++++--- .../src/test/kotlin/CommandLineTest.kt | 6 +++--- .../src/test/kotlin/Hips2FitsServiceTest.kt | 9 ++++----- .../test/kotlin/PixInsightPlateSolverTest.kt | 8 ++++++-- .../nebulosa/retrofit/RetrofitService.kt | 20 ++++++++++--------- nebulosa-siril/src/test/kotlin/SirilTest.kt | 4 ++-- nebulosa-wcs/src/test/kotlin/LibWCSTest.kt | 14 +++++++++++-- 8 files changed, 47 insertions(+), 29 deletions(-) diff --git a/nebulosa-astrometrynet-jna/src/test/kotlin/LibAstrometryNetTest.kt b/nebulosa-astrometrynet-jna/src/test/kotlin/LibAstrometryNetTest.kt index b2a9d7bb5..24dc7b26d 100644 --- a/nebulosa-astrometrynet-jna/src/test/kotlin/LibAstrometryNetTest.kt +++ b/nebulosa-astrometrynet-jna/src/test/kotlin/LibAstrometryNetTest.kt @@ -17,7 +17,7 @@ import kotlin.math.min class LibAstrometryNetTest : Solver.RecordMatchCallback { init { - System.setProperty("LIBASTROMETRYNET_PATH", "/home/tiagohm/Git/astrometry.net/solver/libastrometry.so") + System.setProperty(LibAstrometryNet.PATH, "$homeDirectory/Git/astrometry.net/solver/libastrometry.so") } @Test @@ -58,7 +58,7 @@ class LibAstrometryNetTest : Solver.RecordMatchCallback { @Test fun openXyls() { - val xyls = LibAstrometryNet.INSTANCE.xylist_open("/home/tiagohm/Git/astrometry.net/solver/apod4.xy") + val xyls = LibAstrometryNet.INSTANCE.xylist_open("$homeDirectory/Git/astrometry.net/solver/apod4.xy") xyls.xname shouldBe "X" xyls.yname shouldBe "Y" xyls.xtype shouldBeExactly 8 @@ -99,7 +99,7 @@ class LibAstrometryNetTest : Solver.RecordMatchCallback { LibAstrometryNet.INSTANCE.solver_add_index(solver, index) } - val xyls = LibAstrometryNet.INSTANCE.xylist_open("/home/tiagohm/Git/astrometry.net/solver/apod4.xy") + val xyls = LibAstrometryNet.INSTANCE.xylist_open("$homeDirectory/Git/astrometry.net/solver/apod4.xy") val xy = LibAstrometryNet.INSTANCE.xylist_read_field(xyls, null) LibAstrometryNet.INSTANCE.solver_reset_counters(solver) LibAstrometryNet.INSTANCE.solver_reset_best_match(solver) diff --git a/nebulosa-common/src/main/kotlin/nebulosa/common/exec/CommandLine.kt b/nebulosa-common/src/main/kotlin/nebulosa/common/exec/CommandLine.kt index 73a923280..2f34a5c0f 100644 --- a/nebulosa-common/src/main/kotlin/nebulosa/common/exec/CommandLine.kt +++ b/nebulosa-common/src/main/kotlin/nebulosa/common/exec/CommandLine.kt @@ -129,14 +129,17 @@ data class CommandLine internal constructor( override fun run() { try { - if (timeout > 0L) { + val exited = if (timeout > 0L) { process.waitFor(timeout, TimeUnit.MILLISECONDS) } else { process.waitFor() + true } - inputReader?.waitFor() - errorReader?.waitFor() + if (exited) { + inputReader?.waitFor() + errorReader?.waitFor() + } } catch (ignored: InterruptedException) { } finally { if (process.isAlive) { diff --git a/nebulosa-common/src/test/kotlin/CommandLineTest.kt b/nebulosa-common/src/test/kotlin/CommandLineTest.kt index 80ddb23c8..fdfcf58f3 100644 --- a/nebulosa-common/src/test/kotlin/CommandLineTest.kt +++ b/nebulosa-common/src/test/kotlin/CommandLineTest.kt @@ -6,14 +6,14 @@ import io.kotest.matchers.longs.shouldBeGreaterThanOrEqual import io.kotest.matchers.longs.shouldBeLessThan import nebulosa.common.exec.CommandLineListener import nebulosa.common.exec.commandLine -import nebulosa.test.NonGitHubOnly +import nebulosa.test.LinuxOnly import org.junit.jupiter.api.Test import java.nio.file.Path import java.time.Duration import kotlin.concurrent.thread import kotlin.system.measureTimeMillis -@NonGitHubOnly +@LinuxOnly class CommandLineTest { @Test @@ -37,7 +37,7 @@ class CommandLineTest { measureTimeMillis { cmd.start(Duration.ofSeconds(2)).get() shouldNotBeExactly 0 - } shouldBeGreaterThanOrEqual 2000 + } shouldBeGreaterThanOrEqual 2000 shouldBeLessThan 10000 } @Test diff --git a/nebulosa-hips2fits/src/test/kotlin/Hips2FitsServiceTest.kt b/nebulosa-hips2fits/src/test/kotlin/Hips2FitsServiceTest.kt index 4c0b5fd7a..2d0101233 100644 --- a/nebulosa-hips2fits/src/test/kotlin/Hips2FitsServiceTest.kt +++ b/nebulosa-hips2fits/src/test/kotlin/Hips2FitsServiceTest.kt @@ -10,19 +10,16 @@ import nebulosa.io.source import nebulosa.math.deg import nebulosa.math.toDegrees import nebulosa.test.HTTP_CLIENT -import nebulosa.test.NonGitHubOnly +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -@NonGitHubOnly class Hips2FitsServiceTest { @Test fun query() { val responseBody = SERVICE .query("CDS/P/DSS2/red", 201.36506337683.deg, (-43.01911250808).deg) - .execute() - .body() - .shouldNotBeNull() + .execute().body().shouldNotBeNull() val fits = responseBody.use { it.bytes().source().fits() } val hdu = fits.filterIsInstance().first().header hdu.width shouldBeExactly 1200 @@ -32,7 +29,9 @@ class Hips2FitsServiceTest { } @Test + @Disabled fun availableSurveys() { + // Invalid UTF-8 start byte 0xb0. The API returns charset=ISO-8859-1. val surveys = SERVICE.availableSurveys().execute().body().shouldNotBeNull() surveys.shouldNotBeEmpty() surveys shouldHaveSize 115 diff --git a/nebulosa-pixinsight/src/test/kotlin/PixInsightPlateSolverTest.kt b/nebulosa-pixinsight/src/test/kotlin/PixInsightPlateSolverTest.kt index 79349cd4d..a073f27b3 100644 --- a/nebulosa-pixinsight/src/test/kotlin/PixInsightPlateSolverTest.kt +++ b/nebulosa-pixinsight/src/test/kotlin/PixInsightPlateSolverTest.kt @@ -16,10 +16,9 @@ class PixInsightPlateSolverTest : AbstractTest() { @Test fun solver() { - val runner = PixInsightScriptRunner(Path.of("PixInsight")) val pixelSize = 6.58 val resolution = 6.78.arcsec - val solver = PixInsightPlateSolver(runner, pixelSize, resolution = resolution) + val solver = PixInsightPlateSolver(RUNNER, pixelSize, resolution = resolution) val path = download("https://nova.astrometry.net/image/14603", "jpg") val centerRA = "06 40 51".hours val centerDEC = "09 49 53".deg @@ -34,4 +33,9 @@ class PixInsightPlateSolverTest : AbstractTest() { solution.widthInPixels.roundToInt() shouldBeExactly 800 solution.heightInPixels.roundToInt() shouldBeExactly 526 } + + companion object { + + @JvmStatic val RUNNER = PixInsightScriptRunner(Path.of("PixInsight")) + } } diff --git a/nebulosa-retrofit/src/main/kotlin/nebulosa/retrofit/RetrofitService.kt b/nebulosa-retrofit/src/main/kotlin/nebulosa/retrofit/RetrofitService.kt index 34bd3b82f..c84f606c1 100644 --- a/nebulosa-retrofit/src/main/kotlin/nebulosa/retrofit/RetrofitService.kt +++ b/nebulosa-retrofit/src/main/kotlin/nebulosa/retrofit/RetrofitService.kt @@ -4,8 +4,8 @@ import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.MapperFeature import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.databind.json.JsonMapper import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule +import com.fasterxml.jackson.module.kotlin.jsonMapper import okhttp3.ConnectionPool import okhttp3.OkHttpClient import retrofit2.CallAdapter @@ -22,9 +22,11 @@ abstract class RetrofitService( protected val jsonMapper: ObjectMapper by lazy { mapper ?: DEFAULT_MAPPER.copy() } - protected open val converterFactory = emptyList() + protected open val converterFactory: Iterable + get() = emptyList() - protected open val callAdaptorFactory: CallAdapter.Factory? = null + protected open val callAdaptorFactory: CallAdapter.Factory? + get() = null protected open fun withOkHttpClientBuilder(builder: OkHttpClient.Builder) = Unit @@ -61,11 +63,11 @@ abstract class RetrofitService( .callTimeout(60L, TimeUnit.SECONDS) .build() - @JvmStatic private val DEFAULT_MAPPER = JsonMapper.builder() - .addModule(JavaTimeModule()) - .serializationInclusion(JsonInclude.Include.NON_NULL) - .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS) - .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) - .build()!! + @JvmStatic private val DEFAULT_MAPPER = jsonMapper { + addModule(JavaTimeModule()) + enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS) + disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + serializationInclusion(JsonInclude.Include.NON_NULL) + } } } diff --git a/nebulosa-siril/src/test/kotlin/SirilTest.kt b/nebulosa-siril/src/test/kotlin/SirilTest.kt index bff8557e2..26d489523 100644 --- a/nebulosa-siril/src/test/kotlin/SirilTest.kt +++ b/nebulosa-siril/src/test/kotlin/SirilTest.kt @@ -44,8 +44,7 @@ class SirilTest : AbstractTest() { @Test fun plateSolver() { - val solver = SirilPlateSolver(EXECUTABLE_PATH) - val solution = solver.solve(PI_01_LIGHT, null) + val solution = SOLVER.solve(PI_01_LIGHT, null) solution.solved.shouldBeTrue() solution.orientation.toDegrees shouldBe (-90.02 plusOrMinus 1e-2) @@ -82,5 +81,6 @@ class SirilTest : AbstractTest() { companion object { @JvmStatic private val EXECUTABLE_PATH = Path.of("siril-cli") + @JvmStatic private val SOLVER = SirilPlateSolver(EXECUTABLE_PATH) } } diff --git a/nebulosa-wcs/src/test/kotlin/LibWCSTest.kt b/nebulosa-wcs/src/test/kotlin/LibWCSTest.kt index 315101eca..d2053c6b6 100644 --- a/nebulosa-wcs/src/test/kotlin/LibWCSTest.kt +++ b/nebulosa-wcs/src/test/kotlin/LibWCSTest.kt @@ -4,15 +4,18 @@ import nebulosa.fits.fits import nebulosa.image.format.ReadableHeader import nebulosa.math.formatHMS import nebulosa.math.formatSignedDMS -import nebulosa.test.NonGitHubOnly +import nebulosa.test.LinuxOnly +import nebulosa.test.download +import nebulosa.wcs.LibWCS import nebulosa.wcs.WCS +import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import java.nio.file.Path import kotlin.random.Random // https://www.atnf.csiro.au/people/mcalabre/WCS/example_data.html -@NonGitHubOnly +@LinuxOnly class LibWCSTest { @Test @@ -134,6 +137,13 @@ class LibWCSTest { companion object { + @BeforeAll + @JvmStatic + fun loadLibWCS() { + val libPath = download("https://github.com/tiagohm/nebulosa.data/raw/main/wcs/linux-x86-64/libwcs.so") + System.setProperty(LibWCS.PATH, "$libPath") + } + @JvmStatic private fun pixToSky(projectionName: String, width: Int, height: Int) { val data = Array(2048) { intArrayOf(Random.nextInt(width), Random.nextInt(height)) }