remove tracker type (#4723)
There is a test seam in the engine that counts verification overlaps. This commit converts it from a bespoke mutex-wrapping-an-int type to a simple atomic integer. This is a minor thing but by gum I just love deleting code so much that I can't help myself.
This commit is contained in:
+2
-13
@@ -213,7 +213,7 @@ type Engine struct {
|
||||
verify bool
|
||||
|
||||
// Note: bad hack only used for testing.
|
||||
verificationOverlapTracker *verificationOverlapTracker
|
||||
verificationOverlapTracker *atomic.Int32
|
||||
|
||||
// detectorWorkerMultiplier is used to calculate the number of detector workers.
|
||||
detectorWorkerMultiplier int
|
||||
@@ -534,17 +534,6 @@ func (e *Engine) initialize(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type verificationOverlapTracker struct {
|
||||
verificationOverlapDuplicateCount int
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func (r *verificationOverlapTracker) increment() {
|
||||
r.mu.Lock()
|
||||
r.verificationOverlapDuplicateCount++
|
||||
r.mu.Unlock()
|
||||
}
|
||||
|
||||
const ignoreTag = "trufflehog:ignore"
|
||||
|
||||
// AhoCorasickCoreKeywords returns a set of keywords that the engine's
|
||||
@@ -995,7 +984,7 @@ func (e *Engine) verificationOverlapWorker(ctx context.Context) {
|
||||
// This indicates that the same secret was found by multiple detectors.
|
||||
// We should NOT VERIFY this chunk's data.
|
||||
if e.verificationOverlapTracker != nil {
|
||||
e.verificationOverlapTracker.increment()
|
||||
e.verificationOverlapTracker.Add(1)
|
||||
}
|
||||
res.SetVerificationError(errOverlap)
|
||||
e.processResult(
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -767,7 +768,7 @@ func TestVerificationOverlapChunk(t *testing.T) {
|
||||
e, err := NewEngine(ctx, &c)
|
||||
assert.NoError(t, err)
|
||||
|
||||
e.verificationOverlapTracker = new(verificationOverlapTracker)
|
||||
e.verificationOverlapTracker = &atomic.Int32{}
|
||||
|
||||
e.Start(ctx)
|
||||
|
||||
@@ -783,8 +784,8 @@ func TestVerificationOverlapChunk(t *testing.T) {
|
||||
assert.Equal(t, want, e.GetMetrics().UnverifiedSecretsFound)
|
||||
|
||||
// We want 0 because these are custom detectors and verification should still occur.
|
||||
wantDupe := 0
|
||||
assert.Equal(t, wantDupe, e.verificationOverlapTracker.verificationOverlapDuplicateCount)
|
||||
wantDupe := int32(0)
|
||||
assert.Equal(t, wantDupe, e.verificationOverlapTracker.Load())
|
||||
}
|
||||
|
||||
func TestEngine_FalsePositivesRetainedCorrectly(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user