Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Show delay default value as 500ms. Response Time Display value. Change Save Button TextButton -> Button #32

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Close
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LargeTopAppBar
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Slider
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -69,14 +69,13 @@ fun FlakerPrefsDialog(
}
},
actions = {
TextButton(
onClick = { onConfirmAction(newValues) }
Button(
onClick = { onConfirmAction(newValues) },
) {
Text(
text = "Save",
modifier = Modifier.padding(horizontal = 16.dp)
)
Text(text = "Save")
}

Spacer(modifier = Modifier.size(16.dp))
},
scrollBehavior = scrollBehavior
)
Expand All @@ -91,11 +90,11 @@ fun FlakerPrefsDialog(
title = delayText,
currentValue = delayCurrentValue,
onValueChange = { value ->
if (value >= 1f) {
if (value >= 0.5f) {
newValues = newValues.copy(delay = (round(value).toInt() * HUNDRED_PERCENT))
}
},
discreteSteps = 9,
discreteSteps = 19,
modifier = Modifier.padding(24.dp)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PrefDataStoreImpl(private val prefs: DataStore<Preferences>) : PrefDataSto
return prefs.data.map {
FlakerPrefs(
shouldIntercept = it[FLAKER_SHOULD_INTERCEPT] ?: false,
delay = it[FLAKER_DELAY_VALUE] ?: 0,
delay = it[FLAKER_DELAY_VALUE] ?: 500,
failPercent = it[FLAKER_FAIL_PERCENT] ?: 0,
variancePercent = it[FLAKER_VARIANCE_PERCENT] ?: 0
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,30 @@ class FlakerInterceptor private constructor(
.message(failResponse.message)
.body(failResponse.responseBodyString.toResponseBody("text/plain".toMediaTypeOrNull()))
.request(chain.request())
.sentRequestAtMillis(System.currentTimeMillis() - calculatedDelay)
.sentRequestAtMillis(System.currentTimeMillis())
.receivedResponseAtMillis(System.currentTimeMillis())
.build()

saveNetworkTransaction(request, flakerInterceptedResponse, true)
saveNetworkTransaction(request, flakerInterceptedResponse, calculatedDelay, true)
return@runBlocking flakerInterceptedResponse
}

val nonFlakerInterceptedResponse = chain.proceed(chain.request())
saveNetworkTransaction(request, nonFlakerInterceptedResponse, false)
saveNetworkTransaction(request, nonFlakerInterceptedResponse, calculatedDelay, false)
return@runBlocking nonFlakerInterceptedResponse
} else {
return@runBlocking chain.proceed(chain.request())
}
}

private fun saveNetworkTransaction(request: Request, response: Response, isFailedByFlaker: Boolean) {
private fun saveNetworkTransaction(request: Request, response: Response, delay: Long, isFailedByFlaker: Boolean) {
val networkRequest = NetworkRequest(
host = request.url.host,
path = request.url.pathSegments.joinToString("/"),
method = request.method,
requestTime = response.sentRequestAtMillis,
responseCode = response.code.toLong(),
responseTimeTaken = response.receivedResponseAtMillis,
responseTimeTaken = (response.receivedResponseAtMillis - response.sentRequestAtMillis) + delay,
isFailedByFlaker = isFailedByFlaker
)

Expand Down