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:
@@ -218,6 +218,11 @@ EndProcedure
|
|||||||
; next packets.
|
; next packets.
|
||||||
#BakaShrot_InboxKeptCapacity = 256 * 1024
|
#BakaShrot_InboxKeptCapacity = 256 * 1024
|
||||||
|
|
||||||
|
; How long a send waits for the other end to make room, without a single
|
||||||
|
; byte going out, before it gives up. Same as how long a client waits for
|
||||||
|
; each packet (#BakaShrot_Outbound_Timeout).
|
||||||
|
#BakaShrot_SendStallTimeout = 10000
|
||||||
|
|
||||||
Enumeration BakaShrot_InboxResults
|
Enumeration BakaShrot_InboxResults
|
||||||
#BakaShrot_Inbox_Incomplete
|
#BakaShrot_Inbox_Incomplete
|
||||||
#BakaShrot_Inbox_Packet
|
#BakaShrot_Inbox_Packet
|
||||||
@@ -264,8 +269,13 @@ EndProcedure
|
|||||||
; *Cipher is 0: only the Hello (sealed on its own) and the ChallengeRequest.
|
; *Cipher is 0: only the Hello (sealed on its own) and the ChallengeRequest.
|
||||||
; Returns #False if the packet is too big, *Cipher isn't set up, or the data
|
; Returns #False if the packet is too big, *Cipher isn't set up, or the data
|
||||||
; couldn't be sent.
|
; couldn't be sent.
|
||||||
|
; PureBasic's sockets don't block: SendNetworkData() returns -1 once the
|
||||||
|
; system's send buffer is full (EAGAIN on Linux, a few hundred KB), so -1 is
|
||||||
|
; retried until nothing went out for #BakaShrot_SendStallTimeout. PureBasic
|
||||||
|
; doesn't tell that from a broken connection, which then takes that long to
|
||||||
|
; give up on.
|
||||||
Procedure.i BakaShrot_SendPacket(ConnectionId.i, *Packet, PacketSize.i, *Cipher.BakaShrot_Cipher)
|
Procedure.i BakaShrot_SendPacket(ConnectionId.i, *Packet, PacketSize.i, *Cipher.BakaShrot_Cipher)
|
||||||
Protected *Frame, FrameSize.i, PayloadSize.i, Offset.i, Sent.i
|
Protected *Frame, FrameSize.i, PayloadSize.i, Offset.i, Sent.i, LastProgress.i
|
||||||
|
|
||||||
If PacketSize < 1 Or PacketSize > #BakaShrot_MaxPacketSize
|
If PacketSize < 1 Or PacketSize > #BakaShrot_MaxPacketSize
|
||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
@@ -294,13 +304,19 @@ Procedure.i BakaShrot_SendPacket(ConnectionId.i, *Packet, PacketSize.i, *Cipher.
|
|||||||
CopyMemory(*Packet, *Frame + #BakaShrot_FrameHeaderSize, PacketSize)
|
CopyMemory(*Packet, *Frame + #BakaShrot_FrameHeaderSize, PacketSize)
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
LastProgress = ElapsedMilliseconds()
|
||||||
While Offset < FrameSize
|
While Offset < FrameSize
|
||||||
Sent = SendNetworkData(ConnectionId, *Frame + Offset, FrameSize - Offset)
|
Sent = SendNetworkData(ConnectionId, *Frame + Offset, FrameSize - Offset)
|
||||||
If Sent <= 0
|
If Sent > 0
|
||||||
|
Offset + Sent
|
||||||
|
LastProgress = ElapsedMilliseconds()
|
||||||
|
ElseIf ElapsedMilliseconds() - LastProgress > #BakaShrot_SendStallTimeout
|
||||||
FreeMemory(*Frame)
|
FreeMemory(*Frame)
|
||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
|
Else
|
||||||
|
; Full, until the other end reads some of it.
|
||||||
|
Delay(1)
|
||||||
EndIf
|
EndIf
|
||||||
Offset + Sent
|
|
||||||
Wend
|
Wend
|
||||||
|
|
||||||
FreeMemory(*Frame)
|
FreeMemory(*Frame)
|
||||||
|
|||||||
+33
-15
@@ -10,6 +10,11 @@
|
|||||||
; bundled with PureBasic 5.73 (3.33.0) doesn't have. On Windows, the official
|
; bundled with PureBasic 5.73 (3.33.0) doesn't have. On Windows, the official
|
||||||
; sqlite3.dll is used instead, it must be next to the program. Build.ps1
|
; sqlite3.dll is used instead, it must be next to the program. Build.ps1
|
||||||
; extracts it from Libs/sqlite-dll-win-*.zip and copies it.
|
; extracts it from Libs/sqlite-dll-win-*.zip and copies it.
|
||||||
|
; On Linux, the system's libsqlite3.so.0 (libsqlite3-0 on Debian/Ubuntu,
|
||||||
|
; sqlite-libs on Fedora) is used, whatever the compiler, it must be 3.38+.
|
||||||
|
; Either way it's #BakaShrot_Storage_SqliteLibrary, which RunReadOnlyQuery()
|
||||||
|
; and the writer (Writer.pbi) also call directly. Elsewhere, PureBasic's own
|
||||||
|
; SQLite is linked in, and they make do without it.
|
||||||
;
|
;
|
||||||
; Threads: ONE CONNECTION PER THREAD, never share a handle.
|
; Threads: ONE CONNECTION PER THREAD, never share a handle.
|
||||||
; The SetDatabase*() parameters and query results belong to a handle, so two
|
; The SetDatabase*() parameters and query results belong to a handle, so two
|
||||||
@@ -30,8 +35,20 @@ XIncludeFile "../../Commons/Networking/Packets/SyncStatePacket.pbi"
|
|||||||
XIncludeFile "../../Commons/Networking/Packets/ReplicateMessagesPacket.pbi"
|
XIncludeFile "../../Commons/Networking/Packets/ReplicateMessagesPacket.pbi"
|
||||||
|
|
||||||
|
|
||||||
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
|
CompilerSelect #PB_Compiler_OS
|
||||||
UseSQLiteDatabase("sqlite3.dll")
|
CompilerCase #PB_OS_Windows
|
||||||
|
#BakaShrot_Storage_ExternalSqlite = #True
|
||||||
|
#BakaShrot_Storage_SqliteLibrary = "sqlite3.dll"
|
||||||
|
CompilerCase #PB_OS_Linux
|
||||||
|
#BakaShrot_Storage_ExternalSqlite = #True
|
||||||
|
#BakaShrot_Storage_SqliteLibrary = "libsqlite3.so.0"
|
||||||
|
CompilerDefault
|
||||||
|
#BakaShrot_Storage_ExternalSqlite = #False
|
||||||
|
#BakaShrot_Storage_SqliteLibrary = ""
|
||||||
|
CompilerEndSelect
|
||||||
|
|
||||||
|
CompilerIf #BakaShrot_Storage_ExternalSqlite
|
||||||
|
UseSQLiteDatabase(#BakaShrot_Storage_SqliteLibrary)
|
||||||
CompilerElse
|
CompilerElse
|
||||||
UseSQLiteDatabase()
|
UseSQLiteDatabase()
|
||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
@@ -67,7 +84,7 @@ Procedure.q BakaShrot_NowUtcMs()
|
|||||||
GetSystemTimeAsFileTime_(@FileTime)
|
GetSystemTimeAsFileTime_(@FileTime)
|
||||||
ProcedureReturn (FileTime - 116444736000000000) / 10000
|
ProcedureReturn (FileTime - 116444736000000000) / 10000
|
||||||
CompilerElse
|
CompilerElse
|
||||||
; Untested: Linux isn't built yet. struct timeval, 64-bit.
|
; struct timeval, 64-bit (checked on Linux x64 by Tests/Retention-Test.ps1).
|
||||||
Protected Dim TimeVal.q(1)
|
Protected Dim TimeVal.q(1)
|
||||||
BakaShrot_GetTimeOfDay(@TimeVal(0), 0)
|
BakaShrot_GetTimeOfDay(@TimeVal(0), 0)
|
||||||
ProcedureReturn TimeVal(0) * 1000 + TimeVal(1) / 1000
|
ProcedureReturn TimeVal(0) * 1000 + TimeVal(1) / 1000
|
||||||
@@ -616,15 +633,16 @@ EndProcedure
|
|||||||
; the query looked like it simply had no (more) rows. So once the rows end,
|
; the query looked like it simply had no (more) rows. So once the rows end,
|
||||||
; SQLite itself is asked: sqlite3_errcode() on the connection is SQLITE_DONE
|
; SQLite itself is asked: sqlite3_errcode() on the connection is SQLITE_DONE
|
||||||
; (or SQLITE_ROW/SQLITE_OK) if they really ended, the error otherwise, with
|
; (or SQLITE_ROW/SQLITE_OK) if they really ended, the error otherwise, with
|
||||||
; sqlite3_errmsg16() telling which. Same sqlite3.dll as PureBasic's
|
; sqlite3_errmsg16() telling which. Same #BakaShrot_Storage_SqliteLibrary as
|
||||||
; (DatabaseID() is its sqlite3 handle), like Writer.pbi.
|
; PureBasic's (DatabaseID() is its sqlite3 handle), like Writer.pbi.
|
||||||
; Elsewhere than Windows, PureBasic's own SQLite is linked in and not
|
; Without #BakaShrot_Storage_ExternalSqlite, PureBasic's own SQLite is linked
|
||||||
; reachable this way: DatabaseError() is checked instead, which misses it.
|
; in and not reachable this way: DatabaseError() is checked instead, which
|
||||||
|
; misses it.
|
||||||
#BakaShrot_Query_SqliteOk = 0
|
#BakaShrot_Query_SqliteOk = 0
|
||||||
#BakaShrot_Query_SqliteRow = 100
|
#BakaShrot_Query_SqliteRow = 100
|
||||||
#BakaShrot_Query_SqliteDone = 101
|
#BakaShrot_Query_SqliteDone = 101
|
||||||
|
|
||||||
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
|
CompilerIf #BakaShrot_Storage_ExternalSqlite
|
||||||
PrototypeC.l BakaShrot_Query_SqliteErrCode(Db.i)
|
PrototypeC.l BakaShrot_Query_SqliteErrCode(Db.i)
|
||||||
PrototypeC.i BakaShrot_Query_SqliteErrMsg16(Db.i)
|
PrototypeC.i BakaShrot_Query_SqliteErrMsg16(Db.i)
|
||||||
|
|
||||||
@@ -638,14 +656,14 @@ CompilerIf #PB_Compiler_OS = #PB_OS_Windows
|
|||||||
; Queries run on every client's thread, the first one loads it.
|
; Queries run on every client's thread, the first one loads it.
|
||||||
Global BakaShrot_Query_SqliteMutex.i = CreateMutex()
|
Global BakaShrot_Query_SqliteMutex.i = CreateMutex()
|
||||||
|
|
||||||
; Returns #False if sqlite3.dll or its functions can't be found.
|
; Returns #False if the SQLite library or its functions can't be found.
|
||||||
Procedure.i BakaShrot_Query_LoadSqlite()
|
Procedure.i BakaShrot_Query_LoadSqlite()
|
||||||
Protected Loaded.i
|
Protected Loaded.i
|
||||||
|
|
||||||
LockMutex(BakaShrot_Query_SqliteMutex)
|
LockMutex(BakaShrot_Query_SqliteMutex)
|
||||||
With BakaShrot_Query_Sqlite
|
With BakaShrot_Query_Sqlite
|
||||||
If Not \Library
|
If Not \Library
|
||||||
\Library = OpenLibrary(#PB_Any, "sqlite3.dll")
|
\Library = OpenLibrary(#PB_Any, #BakaShrot_Storage_SqliteLibrary)
|
||||||
If \Library
|
If \Library
|
||||||
\ErrCode = GetFunction(\Library, "sqlite3_errcode")
|
\ErrCode = GetFunction(\Library, "sqlite3_errcode")
|
||||||
\ErrMsg16 = GetFunction(\Library, "sqlite3_errmsg16")
|
\ErrMsg16 = GetFunction(\Library, "sqlite3_errmsg16")
|
||||||
@@ -693,7 +711,7 @@ Procedure.i RunReadOnlyQuery(DatabasePath.s, Sql.s, *Result.String, *Error.Strin
|
|||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
; Without it, errors in the rows would go unnoticed: refused instead.
|
; Without it, errors in the rows would go unnoticed: refused instead.
|
||||||
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
|
CompilerIf #BakaShrot_Storage_ExternalSqlite
|
||||||
If Not BakaShrot_Query_LoadSqlite()
|
If Not BakaShrot_Query_LoadSqlite()
|
||||||
*Error\s = "Queries can't be checked for errors: sqlite3_errcode() not found"
|
*Error\s = "Queries can't be checked for errors: sqlite3_errcode() not found"
|
||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
@@ -767,7 +785,7 @@ Procedure.i RunReadOnlyQuery(DatabasePath.s, Sql.s, *Result.String, *Error.Strin
|
|||||||
; Asked before FinishDatabaseQuery(), while the failed step is the last
|
; Asked before FinishDatabaseQuery(), while the failed step is the last
|
||||||
; thing done on this connection. A false alarm would refuse a good
|
; thing done on this connection. A false alarm would refuse a good
|
||||||
; query, it can't hide a bad one.
|
; query, it can't hide a bad one.
|
||||||
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
|
CompilerIf #BakaShrot_Storage_ExternalSqlite
|
||||||
ErrorCode = BakaShrot_Query_Sqlite\ErrCode(DatabaseID(DbId))
|
ErrorCode = BakaShrot_Query_Sqlite\ErrCode(DatabaseID(DbId))
|
||||||
If ErrorCode <> #BakaShrot_Query_SqliteOk And ErrorCode <> #BakaShrot_Query_SqliteRow And ErrorCode <> #BakaShrot_Query_SqliteDone
|
If ErrorCode <> #BakaShrot_Query_SqliteOk And ErrorCode <> #BakaShrot_Query_SqliteRow And ErrorCode <> #BakaShrot_Query_SqliteDone
|
||||||
*Error\s = PeekS(BakaShrot_Query_Sqlite\ErrMsg16(DatabaseID(DbId)), -1, #PB_Unicode)
|
*Error\s = PeekS(BakaShrot_Query_Sqlite\ErrMsg16(DatabaseID(DbId)), -1, #PB_Unicode)
|
||||||
@@ -785,11 +803,11 @@ Procedure.i RunReadOnlyQuery(DatabasePath.s, Sql.s, *Result.String, *Error.Strin
|
|||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
FinishDatabaseQuery(DbId)
|
FinishDatabaseQuery(DbId)
|
||||||
|
|
||||||
; Elsewhere than Windows, the only check there is. It misses errors in the
|
; Without #BakaShrot_Storage_ExternalSqlite, the only check there is. It
|
||||||
; rows: PureBasic doesn't report them.
|
; misses errors in the rows: PureBasic doesn't report them.
|
||||||
; !!! DatabaseError() may be shared by every thread, see
|
; !!! DatabaseError() may be shared by every thread, see
|
||||||
; !!! Design/StorageConcurrency.md, another thread's error could show up here.
|
; !!! Design/StorageConcurrency.md, another thread's error could show up here.
|
||||||
CompilerIf #PB_Compiler_OS <> #PB_OS_Windows
|
CompilerIf Not #BakaShrot_Storage_ExternalSqlite
|
||||||
If DatabaseError() <> ""
|
If DatabaseError() <> ""
|
||||||
*Error\s = DatabaseError()
|
*Error\s = DatabaseError()
|
||||||
FreeJSON(JsonId)
|
FreeJSON(JsonId)
|
||||||
|
|||||||
@@ -19,9 +19,10 @@
|
|||||||
; that were waiting find theirs done. The busier, the bigger the groups.
|
; that were waiting find theirs done. The busier, the bigger the groups.
|
||||||
; - Prepared statements, kept for as long as the writer is open, through
|
; - Prepared statements, kept for as long as the writer is open, through
|
||||||
; SQLite's own API: PureBasic prepares a statement again on every call.
|
; SQLite's own API: PureBasic prepares a statement again on every call.
|
||||||
; Same sqlite3.dll as PureBasic's (DatabaseID() is its sqlite3 handle).
|
; Same #BakaShrot_Storage_SqliteLibrary as PureBasic's (DatabaseID() is
|
||||||
; Elsewhere than Windows, PureBasic's own SQLite is linked in, so its
|
; its sqlite3 handle). Without #BakaShrot_Storage_ExternalSqlite (see
|
||||||
; functions are used instead (slower, same behaviour).
|
; Storage.pbi), PureBasic's own SQLite is linked in, so its functions
|
||||||
|
; are used instead (slower, same behaviour).
|
||||||
; - The next message id of every topic/node id kept in memory, instead of
|
; - The next message id of every topic/node id kept in memory, instead of
|
||||||
; a MAX(message_id) on every push. Read from the database the first time
|
; a MAX(message_id) on every push. Read from the database the first time
|
||||||
; a pair is pushed to (node_heads, which deleting messages leaves as is:
|
; a pair is pushed to (node_heads, which deleting messages leaves as is:
|
||||||
@@ -62,11 +63,7 @@
|
|||||||
#BakaShrot_Storage_WalSizeLimit = 67108864
|
#BakaShrot_Storage_WalSizeLimit = 67108864
|
||||||
|
|
||||||
|
|
||||||
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
|
#BakaShrot_Storage_RawSqlite = #BakaShrot_Storage_ExternalSqlite
|
||||||
#BakaShrot_Storage_RawSqlite = #True
|
|
||||||
CompilerElse
|
|
||||||
#BakaShrot_Storage_RawSqlite = #False
|
|
||||||
CompilerEndIf
|
|
||||||
|
|
||||||
#BakaShrot_Sqlite_Done = 101
|
#BakaShrot_Sqlite_Done = 101
|
||||||
#BakaShrot_Sqlite_Row = 100
|
#BakaShrot_Sqlite_Row = 100
|
||||||
@@ -387,7 +384,7 @@ CompilerIf #BakaShrot_Storage_RawSqlite
|
|||||||
ProcedureReturn #True
|
ProcedureReturn #True
|
||||||
EndIf
|
EndIf
|
||||||
; The one PureBasic's SQLite driver already loaded.
|
; The one PureBasic's SQLite driver already loaded.
|
||||||
\Library = OpenLibrary(#PB_Any, "sqlite3.dll")
|
\Library = OpenLibrary(#PB_Any, #BakaShrot_Storage_SqliteLibrary)
|
||||||
If Not \Library
|
If Not \Library
|
||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
EndIf
|
EndIf
|
||||||
@@ -527,7 +524,7 @@ Procedure.i OpenStorageWriter(DatabasePath.s, *Error.String)
|
|||||||
|
|
||||||
CompilerIf #BakaShrot_Storage_RawSqlite
|
CompilerIf #BakaShrot_Storage_RawSqlite
|
||||||
If Not BakaShrot_Writer_LoadSqlite()
|
If Not BakaShrot_Writer_LoadSqlite()
|
||||||
*Error\s = "sqlite3.dll doesn't have the functions needed"
|
*Error\s = #BakaShrot_Storage_SqliteLibrary + " doesn't have the functions needed"
|
||||||
BakaShrot_Writer_Release()
|
BakaShrot_Writer_Release()
|
||||||
UnlockMutex(BakaShrot_Storage_WriteMutex)
|
UnlockMutex(BakaShrot_Storage_WriteMutex)
|
||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
|
|||||||
@@ -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
|
$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"
|
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
|
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
|
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"\]\]'
|
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)"
|
"INFO A sends it again at every check-in: $Drops times in 6 s (PeerSyncInterval 1)"
|
||||||
|
|||||||
@@ -283,8 +283,18 @@ finally {
|
|||||||
}
|
}
|
||||||
|
|
||||||
"--- Logs"
|
"--- Logs"
|
||||||
$LogA = Get-Content (Join-Path $Dir "a.log") -Raw
|
# A and B start together: until its first link, the other one may not be
|
||||||
$LogB = Get-Content (Join-Path $Dir "b.log") -Raw
|
# 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 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 "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"
|
Check "B sent A its photo" ($LogB -match "Sent the attachment of photos:garage#1 to 'a'") "checked"
|
||||||
|
|||||||
@@ -299,12 +299,22 @@ try {
|
|||||||
"--- Logs"
|
"--- Logs"
|
||||||
# Up to the last real activity: whichever stops first, the other loses its
|
# Up to the last real activity: whichever stops first, the other loses its
|
||||||
# link to it.
|
# 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) {
|
function Read-Log($Name) {
|
||||||
$L = @(Get-Content (Join-Path $Dir "$Name.log"))
|
$L = @(Get-Content (Join-Path $Dir "$Name.log"))
|
||||||
$End = [array]::IndexOf($L, "Stopping...")
|
$End = [array]::IndexOf($L, "Stopping...")
|
||||||
if ($End -lt 0) { $End = $L.Count }
|
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-- }
|
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"
|
$LogA = Read-Log "a"
|
||||||
$LogB = Read-Log "b"
|
$LogB = Read-Log "b"
|
||||||
|
|||||||
@@ -212,7 +212,9 @@ try {
|
|||||||
Start-Sleep -Seconds 3 # A goes on alone
|
Start-Sleep -Seconds 3 # A goes on alone
|
||||||
Stop-Pusher $PK
|
Stop-Pusher $PK
|
||||||
$KSeen = Read-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)
|
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
|
$SB = Start-Srv "b"; Wait-Port 12416 $SB
|
||||||
@@ -256,7 +258,7 @@ try {
|
|||||||
Start-Sleep -Seconds 3 # B goes on alone
|
Start-Sleep -Seconds 3 # B goes on alone
|
||||||
Stop-Pusher $PG
|
Stop-Pusher $PG
|
||||||
$GSeen = Read-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
|
$SA = Start-Srv "a"; Wait-Port 12415 $SA
|
||||||
Check-Survived "A" "kitchen" $PK $OnA
|
Check-Survived "A" "kitchen" $PK $OnA
|
||||||
|
|||||||
@@ -315,10 +315,20 @@ finally {
|
|||||||
"--- Logs"
|
"--- Logs"
|
||||||
$LogA = Get-Content (Join-Path $Dir "a.log") -Raw
|
$LogA = Get-Content (Join-Path $Dir "a.log") -Raw
|
||||||
$LogB = Get-Content (Join-Path $Dir "b.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 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 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 "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 "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"
|
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
|
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
|
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
|
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.
|
acknowledged before is what must survive.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user