Add network throttling for debugging
This commit is contained in:
1 parent
e4efc6832f
commit
67252cd5d5
2 files changed
+24
No files matched your search
@@ -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
|
#const DISABLE_CACHE = false
|
||||||
|
|
||||||
import "pkg:/source/utils/CryptoUtils.bs"
|
import "pkg:/source/utils/CryptoUtils.bs"
|
||||||
@@ -9,6 +11,8 @@ namespace QrCode
|
|||||||
function Generate(text as string, size as integer, padding as integer, mode = QrCode.QrMode.Byte as QrCode.QrMode) as string
|
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)
|
fileName = m.GetFileName(text, mode, size, padding)
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
#else
|
||||||
#if DISABLE_CACHE
|
#if DISABLE_CACHE
|
||||||
#else
|
#else
|
||||||
fs = CreateObject("roFileSystem")
|
fs = CreateObject("roFileSystem")
|
||||||
@@ -16,6 +20,7 @@ namespace QrCode
|
|||||||
return fileName
|
return fileName
|
||||||
end if
|
end if
|
||||||
#end if
|
#end if
|
||||||
|
#end if
|
||||||
|
|
||||||
qr = new QrCode.QRCode()
|
qr = new QrCode.QRCode()
|
||||||
qr.addData(text, mode)
|
qr.addData(text, mode)
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
|
' DISABLE_CACHE will disable all caching for all requests.
|
||||||
|
' Only use this for debugging purposes.
|
||||||
#const DISABLE_CACHE = false
|
#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/CryptoUtils.bs"
|
||||||
import "pkg:/source/utils/ErrorUtils.bs"
|
import "pkg:/source/utils/ErrorUtils.bs"
|
||||||
@@ -297,8 +302,10 @@ namespace HttpClient
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
#if DISABLE_CACHE
|
#if DISABLE_CACHE
|
||||||
|
#if DEBUG
|
||||||
m._noCache = true
|
m._noCache = true
|
||||||
#end if
|
#end if
|
||||||
|
#end if
|
||||||
|
|
||||||
if m._noCache <> true
|
if m._noCache <> true
|
||||||
cache = HttpClientCache.Get(m)
|
cache = HttpClientCache.Get(m)
|
||||||
@@ -431,6 +438,12 @@ namespace HttpClient
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
if m._sent <> true or m._cache <> invalid
|
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)
|
return new HttpResponse(m, invalid)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
@@ -451,6 +464,12 @@ namespace HttpClient
|
|||||||
|
|
||||||
msg = wait(m._timeoutSeconds * 1000, messagePort)
|
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 <> invalid
|
||||||
if m._cancellation.node <> invalid and m._cancellation.field <> invalid
|
if m._cancellation.node <> invalid and m._cancellation.field <> invalid
|
||||||
' TODO:P2 use a separate node as a cancellation token
|
' TODO:P2 use a separate node as a cancellation token
|
||||||
|
|||||||
Reference in new issue
Block a user