From a4bad90f1f418f735e25814475dad39af5a46d50 Mon Sep 17 00:00:00 2001 From: Elvin Efendi Date: Mon, 3 Dec 2018 15:56:58 +0400 Subject: [PATCH] fix an ewma unit test --- rootfs/etc/nginx/lua/test/balancer/ewma_test.lua | 4 ++-- rootfs/etc/nginx/lua/test/run.lua | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/rootfs/etc/nginx/lua/test/balancer/ewma_test.lua b/rootfs/etc/nginx/lua/test/balancer/ewma_test.lua index 3225b59d2..42d69f580 100644 --- a/rootfs/etc/nginx/lua/test/balancer/ewma_test.lua +++ b/rootfs/etc/nginx/lua/test/balancer/ewma_test.lua @@ -42,8 +42,8 @@ describe("Balancer ewma", function() } } local instance = balancer_ewma:new(backend) - - local stats = { ["10.184.7.40:8080"] = 0.5, ["10.184.97.100:8080"] = 0.3 } + instance.ewma = { ["10.184.7.40:8080"] = 0.5, ["10.184.97.100:8080"] = 0.3 } + instance.ewma_last_touched_at = { ["10.184.7.40:8080"] = ngx.now(), ["10.184.97.100:8080"] = ngx.now() } local peer = instance:balance() assert.equal("10.184.97.100:8080", peer) diff --git a/rootfs/etc/nginx/lua/test/run.lua b/rootfs/etc/nginx/lua/test/run.lua index 56cbb546d..4d20dd233 100644 --- a/rootfs/etc/nginx/lua/test/run.lua +++ b/rootfs/etc/nginx/lua/test/run.lua @@ -32,4 +32,7 @@ end ngx.log = function(...) end ngx.print = function(...) end +-- TODO(elvinefendi) once this is implemented for production (should be!), share the same code +math.randomseed(ngx.time() + ngx.worker.pid()) + require "busted.runner"({ standalone = false })