mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-10-05 19:28:25 +00:00
Merge pull request #4180 from vitorpamplona/claude/hopeful-hawking-6sg3ll
Fix race condition in PoWPublishQueue job removal
This commit is contained in:
+3
-1
@@ -476,9 +476,11 @@ class PoWPublishQueue(
|
||||
dropCheckpoint: Boolean,
|
||||
persisted: Boolean,
|
||||
) {
|
||||
// drop the checkpoint before the entry leaves [jobs]: anyone observing
|
||||
// the job disappear must also see its checkpoint gone.
|
||||
if (persisted && dropCheckpoint) persistence?.remove(jobId)
|
||||
pending.update { it.removing(jobId) }
|
||||
_jobs.update { list -> list.filter { it.id != jobId }.toImmutableList() }
|
||||
if (persisted && dropCheckpoint) persistence?.remove(jobId)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+3
-3
@@ -269,7 +269,7 @@ class ObserverListBenchmark {
|
||||
*/
|
||||
private fun allocatedBytes(): Long {
|
||||
val bean = ManagementFactory.getThreadMXBean() as com.sun.management.ThreadMXBean
|
||||
return bean.getThreadAllocatedBytes(Thread.currentThread().id)
|
||||
return bean.getThreadAllocatedBytes(Thread.currentThread().threadId())
|
||||
}
|
||||
|
||||
private fun measureAllocation(
|
||||
@@ -400,14 +400,14 @@ class ObserverListBenchmark {
|
||||
repeat(threads) { t ->
|
||||
thread {
|
||||
start.await()
|
||||
val before = bean.getThreadAllocatedBytes(Thread.currentThread().id)
|
||||
val before = bean.getThreadAllocatedBytes(Thread.currentThread().threadId())
|
||||
var i = t
|
||||
while (i < ops) {
|
||||
val (e, note) = fx[i % fx.size]
|
||||
subject.new(e, note)
|
||||
i += threads
|
||||
}
|
||||
total.addAndGet(bean.getThreadAllocatedBytes(Thread.currentThread().id) - before)
|
||||
total.addAndGet(bean.getThreadAllocatedBytes(Thread.currentThread().threadId()) - before)
|
||||
done.countDown()
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -42,6 +42,7 @@ import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertIs
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@@ -91,8 +92,7 @@ class Nip88PollTagsTest {
|
||||
@Test
|
||||
fun theSpecsPollExampleParsesFieldForField() {
|
||||
val event = Event.fromJson(specPoll)
|
||||
assertTrue(event is PollEvent)
|
||||
val poll = event as PollEvent
|
||||
val poll = assertIs<PollEvent>(event)
|
||||
|
||||
assertEquals("Pineapple on pizza", poll.content)
|
||||
assertEquals(listOf("qj518h583" to "Yay", "gga6cdnqj" to "Nay"), poll.options().map { it.code to it.label })
|
||||
@@ -104,8 +104,7 @@ class Nip88PollTagsTest {
|
||||
@Test
|
||||
fun theSpecsResponseExampleParsesFieldForField() {
|
||||
val event = Event.fromJson(specResponse)
|
||||
assertTrue(event is PollResponseEvent)
|
||||
val response = event as PollResponseEvent
|
||||
val response = assertIs<PollResponseEvent>(event)
|
||||
|
||||
assertEquals("1fc80cf813f1af33d5a435862b7ef7fb96b47e68a48f1abcadf8081f5a545550", response.poll()?.eventId)
|
||||
// Both tags are read. Which of them counts is the polltype's business, not the parser's.
|
||||
|
||||
Reference in New Issue
Block a user