Skip to content

Commit

Permalink
[api]: Fix CommandLine timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Jul 19, 2024
1 parent 1c45794 commit e969fc9
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions nebulosa-common/src/test/kotlin/CommandLineTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,7 +37,7 @@ class CommandLineTest {

measureTimeMillis {
cmd.start(Duration.ofSeconds(2)).get() shouldNotBeExactly 0
} shouldBeGreaterThanOrEqual 2000
} shouldBeGreaterThanOrEqual 2000 shouldBeLessThan 10000
}

@Test
Expand Down
9 changes: 4 additions & 5 deletions nebulosa-hips2fits/src/test/kotlin/Hips2FitsServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageHdu>().first().header
hdu.width shouldBeExactly 1200
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,9 +22,11 @@ abstract class RetrofitService(

protected val jsonMapper: ObjectMapper by lazy { mapper ?: DEFAULT_MAPPER.copy() }

protected open val converterFactory = emptyList<Converter.Factory>()
protected open val converterFactory: Iterable<Converter.Factory>
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

Expand Down Expand Up @@ -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)
}
}
}
4 changes: 2 additions & 2 deletions nebulosa-siril/src/test/kotlin/SirilTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
14 changes: 12 additions & 2 deletions nebulosa-wcs/src/test/kotlin/LibWCSTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) }
Expand Down

0 comments on commit e969fc9

Please sign in to comment.