<commit_before>package lmdb

import (
	"bytes"
	"encoding/binary"
	"fmt"
	"os"
	"runtime"
	"syscall"
	"testing"
	"time"
)

func TestTxn_errLogf(t *testing.T) {
	env := setup(t)
	defer clean(env, t)
	txn, err := env.BeginTxn(nil, 0)
	if err != nil {
		t.Error(err)
	} else {
		defer txn.Abort()
		txn.errf("this is just a test")
	}
}

func TestTxn_finalizer(t *testing.T) {
	env := setup(t)
	defer clean(env, t)

	called := false
	func() {
		txn, err := env.BeginTxn(nil, 0)
		if err != nil {
			t.Error(err)
		} else {
			txn.errLogf = func(string, ...interface{}) {
				called = true
			}
		}
	}()

	runtime.GC()
	runtime.Gosched()
	time.Sleep(100 * time.Nanosecond)

	if !called {
		t.Errorf("error logging function was not called")
	}
}

func TestTxn_Drop(t *testing.T) {
	env := setup(t)
	defer clean(env, t)

	db, err := openDBI(env, "db", Create)
	if err != nil {
		t.Error(err)
		return
	}

	err = env.Update(func(txn *Txn) (err error) {
		return txn.Put(db, []byte("k"), []byte("v"), 0)<commit_msg>lmdb: fudge the finalize test a bit to make sure it can run<commit_after>package lmdb

import (
	"bytes"
	"encoding/binary"
	"fmt"
	"os"
	"runtime"
	"syscall"
	"testing"
	"time"
)

func TestTxn_errLogf(t *testing.T) {
	env := setup(t)
	defer clean(env, t)
	txn, err := env.BeginTxn(nil, 0)
	if err != nil {
		t.Error(err)
	} else {
		defer txn.Abort()
		txn.errf("this is just a test")
	}
}

func TestTxn_finalizer(t *testing.T) {
	env := setup(t)
	defer clean(env, t)

	called := false
	func() {
		txn, err := env.BeginTxn(nil, 0)
		if err != nil {
			t.Error(err)
		} else {
			txn.errLogf = func(string, ...interface{}) {
				called = true
			}
		}
	}()

	// make sure that finalizer has a chance to get called.  it seems like this
	// may not be consistent across versions of go.
	runtime.GC()
	runtime.Gosched()
	time.Sleep(500 * time.Nanosecond)
	runtime.GC()
	runtime.Gosched()

	if !called {
		t.Errorf("error logging function was not called")
	}
}

func TestTxn_Drop(t *testing.T) {
	env := setup(t)
	defer clean(env, t)

	db, err := openDBI(env, "db", Create)
	if err != nil {
		t.Error(err)
		return
	}

	err = env.Update(func(txn *Txn) (err error) {
		return txn.Put(db, []byte("k"), []byte("v"), 0)
{'fraction_non_alphanumeric': 0.17095173658096527, 'fraction_numerical': 0.005412719891745603, 'mean_word_length': 3.281853281853282, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1305756', 'n_tokens_mistral': 1010, 'n_tokens_neox': 937, 'n_words': 235}