Skip to content

Clarify usage of WatchSet methods and behaviour of First/Last#118

Merged
radeksimko merged 2 commits intomasterfrom
clarify-usage
Jan 31, 2022
Merged

Clarify usage of WatchSet methods and behaviour of First/Last#118
radeksimko merged 2 commits intomasterfrom
clarify-usage

Conversation

@radeksimko
Copy link
Copy Markdown
Member

@radeksimko radeksimko commented Jan 28, 2022

The behaviour of First/Last methods can be verified using the following simple test:

type Job struct {
	ID string
}

func TestRepro(t *testing.T) {
	dbSchema := &memdb.DBSchema{
		Tables: map[string]*memdb.TableSchema{
			"jobs": {
				Name: "jobs",
				Indexes: map[string]*memdb.IndexSchema{
					"id": {
						Name:    "id",
						Unique:  true,
						Indexer: &memdb.StringFieldIndex{Field: "ID"},
					},
				},
			},
		},
	}

	db, err := memdb.NewMemDB(dbSchema)
	if err != nil {
		t.Fatal(err)
	}

	txn0 := db.Txn(false)

	txn1 := db.Txn(true)
	t.Cleanup(txn1.Abort)
	err = txn1.Insert("jobs", &Job{
		ID: "one",
	})
	if err != nil {
		t.Fatal(err)
	}
	txn1.Commit()

	obj, err := txn0.First("jobs", "id")
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("received obj = %#v", obj)
}
go test ./internal/scheduler -run=TestRepro -v -count=1
=== RUN   TestRepro
    scheduler_test.go:59: received obj = <nil>
--- PASS: TestRepro (0.00s)
PASS
ok  	github.com/hashicorp/terraform-ls/internal/scheduler	0.315s

@radeksimko radeksimko force-pushed the clarify-usage branch 2 times, most recently from d477e45 to 4b8ad53 Compare January 28, 2022 18:44
Comment thread txn.go Outdated
Copy link
Copy Markdown
Contributor

@banks banks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for improving this Radek!

@radeksimko radeksimko merged commit 0176005 into master Jan 31, 2022
@radeksimko radeksimko deleted the clarify-usage branch January 31, 2022 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants