Skip to content

Commit

Permalink
Bug fix: Check to see whether seen[feature_id] was already set while …
Browse files Browse the repository at this point in the history
…waiting for mutex to become available (preventing duplicate false positives)
  • Loading branch information
thisisaaronland committed Oct 12, 2021
1 parent 458a367 commit 779f03a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
10 changes: 9 additions & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,16 @@ func (r *SQLiteSpatialDatabase) inflateSpatialIndexWithChannels(ctx context.Cont
// ID

mu.Lock()
defer mu.Unlock()

// Check to see whether seen[feature_id] has been assigned by another process
// while waiting for mu to become available

if seen[feature_id] {
return
}

seen[feature_id] = true
mu.Unlock()

t4 := time.Now()

Expand Down
33 changes: 15 additions & 18 deletions database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,28 @@ func TestSpatialDatabaseQuery(t *testing.T) {
t.Fatalf("Failed to create SPR filter from inputs, %v", err)
}

spr, err := db.PointInPolygon(ctx, c, f)
for i := 0; i < 50; i++ {
spr, err := db.PointInPolygon(ctx, c, f)

if err != nil {
t.Fatalf("Failed to perform point in polygon query, %v", err)
}
if err != nil {
t.Fatalf("Failed to perform point in polygon query, %v", err)
}

results := spr.Results()
count := len(results)
results := spr.Results()
count := len(results)

for _, r := range results {
fmt.Printf("DEBUG %s %s\n", r.Id(), r.Name())
}

if count != 1 {
t.Fatalf("Expected 1 result but got %d", count)
}
if count != 1 {
t.Fatalf("Expected 1 result but got %d", count)
}

first := results[0]
first := results[0]

if first.Id() != strconv.FormatInt(expected, 10) {
if first.Id() != strconv.FormatInt(expected, 10) {


t.Fatalf("Expected %d but got %s", expected, first.Id())
}
t.Fatalf("Expected %d but got %s", expected, first.Id())
}

}
}

func TestSpatialDatabaseRemoveFeature(t *testing.T) {
Expand Down

0 comments on commit 779f03a

Please sign in to comment.