From af0dad426e332b629a3f9b7d155dc3f3f0dce034 Mon Sep 17 00:00:00 2001 From: PJ Date: Thu, 30 May 2024 11:14:46 +0200 Subject: [PATCH 1/3] worker: fix log --- worker/worker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/worker.go b/worker/worker.go index 60dfb475d..a01813e2f 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -1480,7 +1480,7 @@ func discardTxnOnErr(ctx context.Context, bus Bus, l *zap.SugaredLogger, txn typ ctx, cancel := context.WithTimeout(ctx, 10*time.Second) if dErr := bus.WalletDiscard(ctx, txn); dErr != nil { - l.Errorf("%w: %v, failed to discard txn: %v", *err, errContext, dErr) + l.Errorf("%v: %s, failed to discard txn: %v", *err, errContext, dErr) } cancel() } From 1bc7c7d816c69e71885c46cce1488045b95dfe56 Mon Sep 17 00:00:00 2001 From: PJ Date: Mon, 3 Jun 2024 15:01:13 +0200 Subject: [PATCH 2/3] testing: fix TestScoredHostsRandSelectByScore NDF --- autopilot/contractor/hosts_test.go | 17 ++++++++++++----- autopilot/contractor/hostscore_test.go | 7 ------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/autopilot/contractor/hosts_test.go b/autopilot/contractor/hosts_test.go index 028da682d..8e7116bb4 100644 --- a/autopilot/contractor/hosts_test.go +++ b/autopilot/contractor/hosts_test.go @@ -52,20 +52,27 @@ func TestScoredHostsRandSelectByScore(t *testing.T) { t.Fatal("unexpected") } - // assert select is random on equal inputs - counts := make([]int, 2) + // assert select is random on equal inputs, we calculate the chi-square + // statistic and assert it's less than critical value of 6.635 (1 degree of + // freedom, using alpha of .01) + var counts [2]int hosts = scoredHosts{ {score: .1, host: api.Host{PublicKey: types.PublicKey{1}}}, {score: .1, host: api.Host{PublicKey: types.PublicKey{2}}}, } - for i := 0; i < 100; i++ { + nRuns := 1e5 + for i := 0; i < int(nRuns); i++ { if hosts.randSelectByScore(1)[0].host.PublicKey == (types.PublicKey{1}) { counts[0]++ } else { counts[1]++ } } - if diff := absDiffInt(counts[0], counts[1]); diff > 40 { - t.Fatal("unexpected", counts[0], counts[1], diff) + var chi2 float64 + for i := 0; i < 2; i++ { + chi2 += math.Pow(float64(counts[i])-nRuns/2, 2) / nRuns / 2 + } + if chi2 > 6.635 { + t.Fatal("unexpected", counts[0], counts[1], chi2) } } diff --git a/autopilot/contractor/hostscore_test.go b/autopilot/contractor/hostscore_test.go index f6d3b12b2..41347ec72 100644 --- a/autopilot/contractor/hostscore_test.go +++ b/autopilot/contractor/hostscore_test.go @@ -240,10 +240,3 @@ func TestCollateralScore(t *testing.T) { t.Errorf("expected %v but got %v", 0, s) } } - -func absDiffInt(x, y int) int { - if x < y { - return y - x - } - return x - y -} From 0a5728a25e5aa9d03139061f2dfb1f5c5499a140 Mon Sep 17 00:00:00 2001 From: PJ Date: Tue, 4 Jun 2024 14:16:44 +0200 Subject: [PATCH 3/3] testing: fix mistake --- autopilot/contractor/hosts_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autopilot/contractor/hosts_test.go b/autopilot/contractor/hosts_test.go index 8e7116bb4..b2aacb1af 100644 --- a/autopilot/contractor/hosts_test.go +++ b/autopilot/contractor/hosts_test.go @@ -70,7 +70,7 @@ func TestScoredHostsRandSelectByScore(t *testing.T) { } var chi2 float64 for i := 0; i < 2; i++ { - chi2 += math.Pow(float64(counts[i])-nRuns/2, 2) / nRuns / 2 + chi2 += math.Pow(float64(counts[i])-nRuns/2, 2) / (nRuns / 2) } if chi2 > 6.635 { t.Fatal("unexpected", counts[0], counts[1], chi2)