From 67252cd5d5281026faa728500b81c0fe2d48b19c Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sat, 16 Mar 2024 13:49:33 -0400 Subject: [PATCH] Add network throttling for debugging --- playlet-lib/src/source/QrCode/QrImage.bs | 15 ++++++++----- playlet-lib/src/source/services/HttpClient.bs | 21 ++++++++++++++++++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/playlet-lib/src/source/QrCode/QrImage.bs b/playlet-lib/src/source/QrCode/QrImage.bs index 46d4214b..83960be5 100644 --- a/playlet-lib/src/source/QrCode/QrImage.bs +++ b/playlet-lib/src/source/QrCode/QrImage.bs @@ -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() diff --git a/playlet-lib/src/source/services/HttpClient.bs b/playlet-lib/src/source/services/HttpClient.bs index 51a1b550..0a78c0a4 100644 --- a/playlet-lib/src/source/services/HttpClient.bs +++ b/playlet-lib/src/source/services/HttpClient.bs @@ -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