Add network throttling for debugging

This commit is contained in:
Brahim Hadriche committed 2024-03-16 13:49:33 -04:00
1 parent e4efc6832f
commit 67252cd5d5
2 files changed
+30 -6

No files matched your search

+10 -5
View File
@@ -1,3 +1,5 @@
' DISABLE_CACHE will force the generation of the QRCode every time.
' Only use this for debugging purposes.
#const DISABLE_CACHE = false
import "pkg:/source/utils/CryptoUtils.bs"
@@ -9,12 +11,15 @@ namespace QrCode
function Generate(text as string, size as integer, padding as integer, mode = QrCode.QrMode.Byte as QrCode.QrMode) as string
fileName = m.GetFileName(text, mode, size, padding)
#if DISABLE_CACHE
#if DEBUG
#else
fs = CreateObject("roFileSystem")
if fs.exists(fileName)
return fileName
end if
#if DISABLE_CACHE
#else
fs = CreateObject("roFileSystem")
if fs.exists(fileName)
return fileName
end if
#end if
#end if
qr = new QrCode.QRCode()
+20 -1
View File
@@ -1,4 +1,9 @@
' DISABLE_CACHE will disable all caching for all requests.
' Only use this for debugging purposes.
#const DISABLE_CACHE = false
' NETWORK_THROTTLE will add a random delay to all requests to simulate network latency.
' Only use this for debugging purposes.
#const NETWORK_THROTTLE = false
import "pkg:/source/utils/CryptoUtils.bs"
import "pkg:/source/utils/ErrorUtils.bs"
@@ -297,7 +302,9 @@ namespace HttpClient
end if
#if DISABLE_CACHE
m._noCache = true
#if DEBUG
m._noCache = true
#end if
#end if
if m._noCache <> true
@@ -431,6 +438,12 @@ namespace HttpClient
end if
if m._sent <> true or m._cache <> invalid
#if NETWORK_THROTTLE
#if DEBUG
sleep(1000 + Rnd(2000))
#end if
#end if
return new HttpResponse(m, invalid)
end if
@@ -451,6 +464,12 @@ namespace HttpClient
msg = wait(m._timeoutSeconds * 1000, messagePort)
#if NETWORK_THROTTLE
#if DEBUG
sleep(1000 + Rnd(2000))
#end if
#end if
if m._cancellation <> invalid
if m._cancellation.node <> invalid and m._cancellation.field <> invalid
' TODO:P2 use a separate node as a cancellation token