Skip to content
quarry Artifact [811ab2124b]
Login

Artifact [811ab2124b]

Artifact 811ab2124b3760c94aeae01b0c5a5da32c34d250d41d3e45bbd7084fe9b2e23a:


package index

import "testing"

// A bulk rebuild recreates its dropped indexes with the sort on disk,
// then hands the writer back to in-memory temp tables: on netbsd-src
// the in-memory sort ran SQLite out of memory and took the forge down.
func TestResumeRebuildsIndexesAndRestoresTempStore(t *testing.T) {
	ix := openIndex(t)
	if err := ix.SuspendDerivedMaintenance(); err != nil {
		t.Fatal(err)
	}
	if err := ix.ResumeDerivedMaintenance(); err != nil {
		t.Fatal(err)
	}
	for _, name := range bulkDroppable {
		var n int
		if err := ix.w.QueryRow(`SELECT count(*) FROM sqlite_master WHERE type = 'index' AND name = ?`, name).Scan(&n); err != nil {
			t.Fatal(err)
		}
		if n != 1 {
			t.Errorf("FAIL: index %s not rebuilt", name)
		}
	}
	var store int
	if err := ix.w.QueryRow(`PRAGMA temp_store`).Scan(&store); err != nil {
		t.Fatal(err)
	}
	if store != 2 {
		t.Errorf("FAIL: temp_store is %d after the rebuild, want 2 (memory)", store)
	}
}