Skip to content
Open
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 @@ -29,6 +29,8 @@ import rs.wordpress.example.shared.ui.components.PostCard
fun StressTestScreen(viewModel: StressTestViewModel = koinInject()) {
val posts by viewModel.posts.collectAsState()
val totalUpdates by viewModel.totalUpdates.collectAsState()
val totalInserts by viewModel.totalInserts.collectAsState()
val totalDeletes by viewModel.totalDeletes.collectAsState()
val isRunning by viewModel.isRunning.collectAsState()
val performanceMetrics by viewModel.performanceMetrics.collectAsState()
val listState = rememberLazyListState()
Expand All @@ -51,7 +53,8 @@ fun StressTestScreen(viewModel: StressTestViewModel = koinInject()) {
)
Spacer(modifier = Modifier.height(8.dp))
Text(text = "Total Posts: ${posts.size}")
Text(text = "Total Updates: $totalUpdates")
Text(text = "Updates: $totalUpdates | Inserts: $totalInserts | Deletes: $totalDeletes")
Text(text = "Total Operations: ${totalUpdates + totalInserts + totalDeletes}")
Text(text = "Status: ${if (isRunning) "Running" else "Stopped"}")

performanceMetrics?.let { metrics ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class StressTestViewModel(
private val _totalUpdates = MutableStateFlow(0L)
val totalUpdates: StateFlow<Long> = _totalUpdates.asStateFlow()

private val _totalInserts = MutableStateFlow(0L)
val totalInserts: StateFlow<Long> = _totalInserts.asStateFlow()

private val _totalDeletes = MutableStateFlow(0L)
val totalDeletes: StateFlow<Long> = _totalDeletes.asStateFlow()

private val _isRunning = MutableStateFlow(false)
val isRunning: StateFlow<Boolean> = _isRunning.asStateFlow()

Expand Down Expand Up @@ -132,9 +138,6 @@ class StressTestViewModel(

// Update performance metrics
updatePerformanceMetrics(loadDuration, totalLatency)

// Increment total updates counter
_totalUpdates.value += 1
}
}

Expand All @@ -145,14 +148,32 @@ class StressTestViewModel(
// Start comprehensive stress test with:
// - 10-100ms delay between batches (variable timing)
// - 1-20 posts per batch (variable batch size)
// - 50% updates, 25% deletes, 25% inserts (operation weights)
stressTestHandle = mockPostService.startComprehensiveStressTest(
entityIds,
minDelayMs = 10u,
maxDelayMs = 100u,
minBatchSize = 1u,
maxBatchSize = 20u
uniffi.wp_mobile.StressTestConfig(
minDelayMs = 10u,
maxDelayMs = 100u,
minBatchSize = 1u,
maxBatchSize = 20u,
updateWeight = 50u,
deleteWeight = 25u,
insertWeight = 25u
)
)
println("Comprehensive stress test started with ObservableCollection!")
println("Comprehensive stress test started with ObservableCollection (updates/deletes/inserts)!")

// Poll operation counters from the stress test handle
viewModelScope.launch(Dispatchers.Default) {
while (_isRunning.value) {
stressTestHandle?.let { handle ->
_totalUpdates.value = handle.updateCount().toLong()
_totalInserts.value = handle.insertCount().toLong()
_totalDeletes.value = handle.deleteCount().toLong()
}
kotlinx.coroutines.delay(100) // Poll every 100ms
}
}
}

private fun updatePerformanceMetrics(loadDuration: Long, totalLatency: Long) {
Expand Down Expand Up @@ -203,6 +224,9 @@ class StressTestViewModel(
}

fun onCleared() {
// Stop the running flag to stop polling
_isRunning.value = false

// Stop background updates
stressTestHandle?.stop()

Expand Down
Loading