Add some tests for singlethreaded usage of the Finder.
Also change the existing tests to use exactly 2 threads.
Also update some tests to also same number of threads as will
be used by the finder.
Bug: 62455338
Test: m -j # which runs unit tests
Change-Id: I2b9d39680ecddd6d28c951df982ac51c077d2777
diff --git a/finder/finder.go b/finder/finder.go
index c2df928..ffda155 100644
--- a/finder/finder.go
+++ b/finder/finder.go
@@ -18,6 +18,7 @@
"bufio"
"bytes"
"encoding/json"
+ "errors"
"fmt"
"io"
"os"
@@ -30,7 +31,6 @@
"time"
"android/soong/fs"
- "errors"
)
// This file provides a Finder struct that can quickly search for files satisfying
@@ -159,11 +159,17 @@
nodes pathMap
}
+var defaultNumThreads = runtime.NumCPU() * 2
+
// New creates a new Finder for use
func New(cacheParams CacheParams, filesystem fs.FileSystem,
logger Logger, dbPath string) (f *Finder, err error) {
+ return newImpl(cacheParams, filesystem, logger, dbPath, defaultNumThreads)
+}
- numThreads := runtime.NumCPU() * 2
+// newImpl is like New but accepts more params
+func newImpl(cacheParams CacheParams, filesystem fs.FileSystem,
+ logger Logger, dbPath string, numThreads int) (f *Finder, err error) {
numDbLoadingThreads := numThreads
numSearchingThreads := numThreads