mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Fix the server on Linux, and test races it showed
Server: - Storage: #BakaShrot_Storage_SqliteLibrary, the SQLite the server loads: sqlite3.dll on Windows, the system's libsqlite3.so.0 on Linux (PB 5.73's bundled 3.33 has no JSON functions). The query error check and the writer's prepared statements use it too, so a JSON function on a row that isn't JSON is refused on Linux as well, not answered with no rows. - SendPacket: SendNetworkData() returns -1 once the send buffer is full (EAGAIN on Linux), which aborted clients reading big answers. Retried until nothing goes out for #BakaShrot_SendStallTimeout (10 s). Tests, timing they relied on: - Attachments, BigMessages: link failures before the first link are expected, Linux refuses at once where Windows retries for ~1 s. - Restart: a pusher whose server is killed between two pushes sees 100 (NotConnected), during one 104 (ConnectionLost): both accepted. - Retention: deletions counted over every retention check, a batch can be split over two. - AttachmentEdges: waits for B's corrupted attachment to be dropped, A sends it again at every check-in. All tests pass on Linux with PB 6.41 (asm and C backends). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RwFeVQCBfcPDfAPqX8z2TF
This commit is contained in:
@@ -270,7 +270,9 @@ db.commit(); print("flipped")
|
||||
$Drops = [regex]::Matches($LogB, "attachment of logs:kitchen#$BadId from peer 'a' doesn't match its SHA-256, dropped").Count
|
||||
Check "B drops it: doesn't match" ($Drops -ge 1) "$Drops times in 6 s"
|
||||
Expect "B doesn't serve it" (Tool "BakaShrotGetAttachment.exe" @("logs", "kitchen", $BadId, $Copy, $KitchenB)) "isn't here yet" 1
|
||||
$R = Query "SELECT a.state, COALESCE(a.blob_id, 0) FROM attachments a JOIN topics t ON t.topic_id = a.topic_id WHERE t.name = 'logs' AND a.message_id = $BadId" $KitchenB
|
||||
# A sends it again at every check-in, so B can be receiving (1) it
|
||||
# again when asked: back to missing once that copy is dropped too.
|
||||
$R = Wait-Query "SELECT a.state, COALESCE(a.blob_id, 0) FROM attachments a JOIN topics t ON t.topic_id = a.topic_id WHERE t.name = 'logs' AND a.message_id = $BadId" $KitchenB '\[\["0","0"\]\]' 5
|
||||
Check "B's attachment is back to missing (0), no blob" ($R.Out -match '\[\["0","0"\]\]') $R.Out
|
||||
Expect "B: no blob left behind, once cleaned" (Wait-Query "SELECT COUNT(*) FROM blobs WHERE state <> 2" $KitchenB '\[\["0"\]\]' 5) '\[\["0"\]\]'
|
||||
"INFO A sends it again at every check-in: $Drops times in 6 s (PeerSyncInterval 1)"
|
||||
|
||||
@@ -283,8 +283,18 @@ finally {
|
||||
}
|
||||
|
||||
"--- Logs"
|
||||
$LogA = Get-Content (Join-Path $Dir "a.log") -Raw
|
||||
$LogB = Get-Content (Join-Path $Dir "b.log") -Raw
|
||||
# A and B start together: until its first link, the other one may not be
|
||||
# listening yet. Refused at once on Linux, while Windows retries the connect
|
||||
# for about a second, by which time it usually is. Those attempts are left out.
|
||||
function Skip-EarlyLinkFailures([string[]]$Lines) {
|
||||
$Linked = $false
|
||||
foreach ($Line in $Lines) {
|
||||
if ($Line -match "^\[Peer\] Linked to") { $Linked = $true }
|
||||
if ($Linked -or $Line -notmatch "^\[Peer\] (Failed to link|Retrying)") { $Line }
|
||||
}
|
||||
}
|
||||
$LogA = @(Skip-EarlyLinkFailures (Get-Content (Join-Path $Dir "a.log"))) -join "`n"
|
||||
$LogB = @(Skip-EarlyLinkFailures (Get-Content (Join-Path $Dir "b.log"))) -join "`n"
|
||||
Check "A sent B the attachments it takes" ($LogA -match "Sent the attachment of logs:kitchen#1 to 'b'" -and $LogA -match "Sent the attachment of logs:kitchen#3 to 'b'") "checked"
|
||||
Check "A never sent #2 (not kept by B)" (-not ($LogA -match "Sent the attachment of logs:kitchen#2")) "checked"
|
||||
Check "B sent A its photo" ($LogB -match "Sent the attachment of photos:garage#1 to 'a'") "checked"
|
||||
|
||||
@@ -299,12 +299,22 @@ try {
|
||||
"--- Logs"
|
||||
# Up to the last real activity: whichever stops first, the other loses its
|
||||
# link to it.
|
||||
# A and B start together: until its first link, the other one may not be
|
||||
# listening yet. Refused at once on Linux, while Windows retries the connect
|
||||
# for about a second, by which time it usually is. Those attempts are left out.
|
||||
function Skip-EarlyLinkFailures([string[]]$Lines) {
|
||||
$Linked = $false
|
||||
foreach ($Line in $Lines) {
|
||||
if ($Line -match "^\[Peer\] Linked to") { $Linked = $true }
|
||||
if ($Linked -or $Line -notmatch "^\[Peer\] (Failed to link|Retrying)") { $Line }
|
||||
}
|
||||
}
|
||||
function Read-Log($Name) {
|
||||
$L = @(Get-Content (Join-Path $Dir "$Name.log"))
|
||||
$End = [array]::IndexOf($L, "Stopping...")
|
||||
if ($End -lt 0) { $End = $L.Count }
|
||||
while ($End -gt 0 -and $L[$End - 1] -match "Lost the link|Dropping the link|Retrying|disconnected|aborted|didn't answer") { $End-- }
|
||||
($L[0..([math]::Max($End - 1, 0))]) -join "`n"
|
||||
@(Skip-EarlyLinkFailures $L[0..([math]::Max($End - 1, 0))]) -join "`n"
|
||||
}
|
||||
$LogA = Read-Log "a"
|
||||
$LogB = Read-Log "b"
|
||||
|
||||
@@ -212,7 +212,9 @@ try {
|
||||
Start-Sleep -Seconds 3 # A goes on alone
|
||||
Stop-Pusher $PK
|
||||
$KSeen = Read-Pusher $PK
|
||||
Check "the garage pusher noticed B was gone: ConnectionLostError, code 104" ($PG.P.HasExited -and (Read-Pusher $PG).End -like "ERR 104 ConnectionLostError*") (Read-Pusher $PG).End
|
||||
# 104 (ConnectionLost) if killed during a push, 100 (NotConnected) if
|
||||
# between two: the next push finds the connection already gone.
|
||||
Check "the garage pusher noticed B was gone: ConnectionLostError, code 104 or 100" ($PG.P.HasExited -and (Read-Pusher $PG).End -match "^ERR 10[04] ConnectionLostError") (Read-Pusher $PG).End
|
||||
Check "kitchen kept pushing on A meanwhile" ($KSeen.Count -gt 100 -and $KSeen.End -eq "STOPPED") ("{0} acknowledged" -f $KSeen.Count)
|
||||
|
||||
$SB = Start-Srv "b"; Wait-Port 12416 $SB
|
||||
@@ -256,7 +258,7 @@ try {
|
||||
Start-Sleep -Seconds 3 # B goes on alone
|
||||
Stop-Pusher $PG
|
||||
$GSeen = Read-Pusher $PG
|
||||
Check "the kitchen pusher noticed A was gone: ConnectionLostError, code 104" ($PK.P.HasExited -and (Read-Pusher $PK).End -like "ERR 104 ConnectionLostError*") (Read-Pusher $PK).End
|
||||
Check "the kitchen pusher noticed A was gone: ConnectionLostError, code 104 or 100" ($PK.P.HasExited -and (Read-Pusher $PK).End -match "^ERR 10[04] ConnectionLostError") (Read-Pusher $PK).End
|
||||
|
||||
$SA = Start-Srv "a"; Wait-Port 12415 $SA
|
||||
Check-Survived "A" "kitchen" $PK $OnA
|
||||
|
||||
@@ -315,10 +315,20 @@ finally {
|
||||
"--- Logs"
|
||||
$LogA = Get-Content (Join-Path $Dir "a.log") -Raw
|
||||
$LogB = Get-Content (Join-Path $Dir "b.log") -Raw
|
||||
# How many messages of Topic a log says were deleted. Pushed a few ms apart,
|
||||
# they can fall on both sides of a retention check (every 1 s), and be
|
||||
# deleted over two of them.
|
||||
function Count-Deleted($Log, $Topic) {
|
||||
$N = 0
|
||||
foreach ($M in [regex]::Matches($Log, "Retention: deleted (\d+) messages of topic '$Topic' pushed before \d{4}-")) { $N += [int]$M.Groups[1].Value }
|
||||
$N
|
||||
}
|
||||
Check "A logged its rule" ($LogA -match "Retention: short = 3s") "checked"
|
||||
Check "A logged what it deleted" ($LogA -match "Retention: deleted 3 messages of topic 'short' pushed before \d{4}-") "checked"
|
||||
$N = Count-Deleted $LogA "short"
|
||||
Check "A logged what it deleted: short #1-#3, maybe #4 since" ($N -ge 3) "$N deleted"
|
||||
Check "B logged its rules" ($LogB -match "Retention: ke\* = 4s" -and $LogB -match "Retention: \* = 1h") "checked"
|
||||
Check "B deleted keep" ($LogB -match "Retention: deleted 2 messages of topic 'keep'") "checked"
|
||||
$N = Count-Deleted $LogB "keep"
|
||||
Check "B deleted keep: #1-#2, maybe #3 since" ($N -ge 2) "$N deleted"
|
||||
Check "B never sent A short messages (A is ahead, deleted or not)" (-not ($LogB -match "Sent \d+ messages of short")) "checked"
|
||||
Check "A sent B late once each: #1-#2, then #3 alone" (([regex]::Matches($LogA, "Sent 2 messages of late:kitchen")).Count -eq 1 -and ([regex]::Matches($LogA, "Sent 1 messages of late:kitchen")).Count -eq 1) "checked"
|
||||
Check "B never stored late #1-#2" (-not ($LogB -match "deleted [23] messages of topic 'late'")) "checked"
|
||||
|
||||
@@ -4,7 +4,8 @@ Usage: restart_pusher.py <BakaShrot_Client.dll> <client.ini> <stop file> <out fi
|
||||
Pushes {"by": tag, "seq": n} to the client's DefaultTopic until the stop
|
||||
file exists, writing "<message id> <seq>" to the out file once each push is
|
||||
acknowledged. Ends with "STOPPED", or "ERR <code> <why>" when the server
|
||||
goes away (the test kills it; code 104, ConnectionLost): what was
|
||||
goes away (the test kills it; code 104, ConnectionLost, during a push, or
|
||||
100, NotConnected, between two): what was
|
||||
acknowledged before is what must survive.
|
||||
"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user