From 0c0e304aace9d759248d763d0e41b33af6dac354 Mon Sep 17 00:00:00 2001 From: Tim Yiu Date: Tue, 19 Sep 2023 11:03:19 -0700 Subject: [PATCH 1/2] fix: Do not track empty assignment events --- pkg/experiment/local/assignment_filter.go | 3 +++ pkg/experiment/local/assignment_filter_test.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/experiment/local/assignment_filter.go b/pkg/experiment/local/assignment_filter.go index 9fd07a1..ed223e6 100644 --- a/pkg/experiment/local/assignment_filter.go +++ b/pkg/experiment/local/assignment_filter.go @@ -19,6 +19,9 @@ func newAssignmentFilter(size int) *assignmentFilter { } func (f *assignmentFilter) shouldTrack(assignment *assignment) bool { + if len(*assignment.results) == 0 { + return false + } canonicalAssignment := assignment.Canonicalize() f.mu.Lock() track, found := f.cache.Get(canonicalAssignment) diff --git a/pkg/experiment/local/assignment_filter_test.go b/pkg/experiment/local/assignment_filter_test.go index d7639d6..5c73612 100644 --- a/pkg/experiment/local/assignment_filter_test.go +++ b/pkg/experiment/local/assignment_filter_test.go @@ -167,13 +167,13 @@ func TestEmptyResult(t *testing.T) { assignment2 := newAssignment(user1, results) assignment3 := newAssignment(user2, results) filter := newAssignmentFilter(100) - if !filter.shouldTrack(assignment1) { + if filter.shouldTrack(assignment1) { t.Errorf("Assignment1 should be tracked") } if filter.shouldTrack(assignment2) { t.Errorf("Assignment2 should not be tracked") } - if !filter.shouldTrack(assignment3) { + if filter.shouldTrack(assignment3) { t.Errorf("Assignment3 should be tracked") } } From 1f0407f2dc6dc1e943a519d0c215a89bdb26074f Mon Sep 17 00:00:00 2001 From: Tim Yiu Date: Tue, 19 Sep 2023 15:40:25 -0700 Subject: [PATCH 2/2] update test error messages --- pkg/experiment/local/assignment_filter_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/experiment/local/assignment_filter_test.go b/pkg/experiment/local/assignment_filter_test.go index 5c73612..ac9b75a 100644 --- a/pkg/experiment/local/assignment_filter_test.go +++ b/pkg/experiment/local/assignment_filter_test.go @@ -168,13 +168,13 @@ func TestEmptyResult(t *testing.T) { assignment3 := newAssignment(user2, results) filter := newAssignmentFilter(100) if filter.shouldTrack(assignment1) { - t.Errorf("Assignment1 should be tracked") + t.Errorf("Assignment1 should not be tracked") } if filter.shouldTrack(assignment2) { t.Errorf("Assignment2 should not be tracked") } if filter.shouldTrack(assignment3) { - t.Errorf("Assignment3 should be tracked") + t.Errorf("Assignment3 should not be tracked") } }