Skip to content

Commit

Permalink
Fix concurrency tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SudoDios committed May 15, 2024
1 parent b787fab commit 29b73bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/main/kotlin/core/Service.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ object Service {

var goToResult : () -> Unit = {}
var onError : (String?) -> Unit = {}
var onEnableAbort : () -> Unit = {}

fun init () {
speedTestHandler = SpeedTestHandler()
Expand Down Expand Up @@ -80,10 +81,9 @@ object Service {

fun startFetchServers (finished : () -> Unit) {
CoroutineScope(Dispatchers.IO).launch {
speedTestHandler.startup()
speedTestHandler.setOnServerSelectListener(object : SpeedTestHandler.OnServerSelectListener{
override fun onError() {

println("Error")
}
override fun onServerSelected(testPoint: TestPoint?) {
this@Service.testPoint.value = testPoint
Expand All @@ -92,6 +92,7 @@ object Service {
}
}
})
speedTestHandler.startup()
}
}

Expand Down Expand Up @@ -139,6 +140,7 @@ object Service {
this@Service.jitter.value = jitter.roundPlace(1).toString()
pingChart.add(ping)
jitterChart.add(jitter)
onEnableAbort.invoke()
}
override fun onIPInfoUpdate(ipInfo: String?) {
this@Service.ipInfo.value = ipInfo.toString()
Expand Down
6 changes: 1 addition & 5 deletions src/main/kotlin/core/SpeedTestHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,8 @@ class SpeedTestHandler {
}
if (data.startsWith("\"") || data.startsWith("'")) { //fetch server list from URL
if (!libreSpeed!!.loadServerList(data.subSequence(1, data.length - 1).toString())) {
try {
throw Exception("Failed to load server list")
} catch (e: Exception) {
e.printStackTrace()
}
onServerSelectListener?.onError()
return
}
} else {
val testPoints = JSONArray(data)
Expand Down
12 changes: 9 additions & 3 deletions src/main/kotlin/routes/sections/home/TestStage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import components.SpeedMeterView
import core.Service
import core.Service.toValidString
import dev.icerock.moko.mvvm.livedata.compose.observeAsState
import kotlinx.coroutines.delay
import theme.ColorBox
import util.Utils.roundPlace
import java.util.Timer
import java.util.TimerTask

@Composable
fun TestStage(onCancel : () -> Unit,goToResult : () -> Unit) {
Expand Down Expand Up @@ -48,8 +49,13 @@ fun TestStage(onCancel : () -> Unit,goToResult : () -> Unit) {
Service.onError = {
onCancel.invoke()
}
delay(3000)
enablecancelation = true
Service.onEnableAbort = {
Timer().schedule(object : TimerTask() {
override fun run() {
enablecancelation = true
}
},2000)
}
}

Box(Modifier.fillMaxSize()) {
Expand Down

0 comments on commit 29b73bf

Please sign in to comment.