Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Rework transaction test framework capabilities #1603

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/data_format_changes/i1602-no-change-tests-updated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Rework transaction test framework capabilities

This is not a breaking change, a test was split, which caused the change detector test-case to change.
35 changes: 18 additions & 17 deletions tests/integration/mutation/relation/create/with_txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ package relation_create
import (
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
"github.com/sourcenetwork/immutable"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
relationTests "github.com/sourcenetwork/defradb/tests/integration/mutation/relation"
)

Expand All @@ -39,8 +40,8 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing.
}`,
},
// Create books related to publishers, and ensure they are correctly linked (in and out of transactions).
testUtils.TransactionRequest2{
TransactionID: 0,
testUtils.Request{
TransactionID: immutable.Some(0),
Request: `mutation {
create_Book(data: "{\"name\": \"Book By Website\",\"rating\": 4.0, \"publisher_id\": \"bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4\"}") {
_key
Expand All @@ -52,8 +53,8 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing.
},
},
},
testUtils.TransactionRequest2{
TransactionID: 1,
testUtils.Request{
TransactionID: immutable.Some(1),
Request: `mutation {
create_Book(data: "{\"name\": \"Book By Online\",\"rating\": 4.0, \"publisher_id\": \"bae-8a381044-9206-51e7-8bc8-dc683d5f2523\"}") {
_key
Expand All @@ -66,8 +67,8 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing.
},
},
// Assert publisher -> books direction within transaction 0.
testUtils.TransactionRequest2{
TransactionID: 0,
testUtils.Request{
TransactionID: immutable.Some(0),
Request: `query {
Publisher {
_key
Expand Down Expand Up @@ -96,8 +97,8 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing.
},
},
// Assert publisher -> books direction within transaction 1.
testUtils.TransactionRequest2{
TransactionID: 1,
testUtils.Request{
TransactionID: immutable.Some(1),
Request: `query {
Publisher {
_key
Expand Down Expand Up @@ -191,8 +192,8 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing
}`,
},
// Create books related to publishers, and ensure they are correctly linked (in and out of transactions).
testUtils.TransactionRequest2{
TransactionID: 0,
testUtils.Request{
TransactionID: immutable.Some(0),
Request: `mutation {
create_Book(data: "{\"name\": \"Book By Website\",\"rating\": 4.0, \"publisher_id\": \"bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4\"}") {
_key
Expand All @@ -204,8 +205,8 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing
},
},
},
testUtils.TransactionRequest2{
TransactionID: 1,
testUtils.Request{
TransactionID: immutable.Some(1),
Request: `mutation {
create_Book(data: "{\"name\": \"Book By Online\",\"rating\": 4.0, \"publisher_id\": \"bae-8a381044-9206-51e7-8bc8-dc683d5f2523\"}") {
_key
Expand All @@ -218,8 +219,8 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing
},
},
// Assert publisher -> books direction within transaction 0.
testUtils.TransactionRequest2{
TransactionID: 0,
testUtils.Request{
TransactionID: immutable.Some(0),
Request: `query {
Book {
_key
Expand All @@ -242,8 +243,8 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing
},
},
// Assert publisher -> books direction within transaction 1.
testUtils.TransactionRequest2{
TransactionID: 1,
testUtils.Request{
TransactionID: immutable.Some(1),
Request: `query {
Book {
_key
Expand Down
35 changes: 18 additions & 17 deletions tests/integration/mutation/relation/delete/with_txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ package relation_delete
import (
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
"github.com/sourcenetwork/immutable"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
relationTests "github.com/sourcenetwork/defradb/tests/integration/mutation/relation"
)

Expand All @@ -41,9 +42,9 @@ func TestTxnDeletionOfRelatedDocFromPrimarySideForwardDirection(t *testing.T) {
"address": "Manning Publications"
}`,
},
testUtils.TransactionRequest2{
testUtils.Request{
// Delete a linked book that exists.
TransactionID: 0,
TransactionID: immutable.Some(0),
Request: `mutation {
delete_Book(id: "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722") {
_key
Expand Down Expand Up @@ -107,9 +108,9 @@ func TestTxnDeletionOfRelatedDocFromPrimarySideBackwardDirection(t *testing.T) {
"address": "Manning Publications"
}`,
},
testUtils.TransactionRequest2{
testUtils.Request{
// Delete a linked book that exists.
TransactionID: 0,
TransactionID: immutable.Some(0),
Request: `mutation {
delete_Book(id: "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722") {
_key
Expand Down Expand Up @@ -167,9 +168,9 @@ func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnForwardDirection(t *tes
"address": "Manning Publications"
}`,
},
testUtils.TransactionRequest2{
testUtils.Request{
// Delete a linked book that exists.
TransactionID: 0,
TransactionID: immutable.Some(0),
Request: `mutation {
delete_Book(id: "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722") {
_key
Expand All @@ -181,9 +182,9 @@ func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnForwardDirection(t *tes
},
},
},
testUtils.TransactionRequest2{
testUtils.Request{
// Read the book (forward) that was deleted (in the non-commited transaction) in another transaction.
TransactionID: 1,
TransactionID: immutable.Some(1),
Request: `query {
Publisher {
_key
Expand Down Expand Up @@ -257,9 +258,9 @@ func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnBackwardDirection(t *te
"address": "Manning Publications"
}`,
},
testUtils.TransactionRequest2{
testUtils.Request{
// Delete a linked book that exists in transaction 0.
TransactionID: 0,
TransactionID: immutable.Some(0),
Request: `mutation {
delete_Book(id: "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722") {
_key
Expand All @@ -271,9 +272,9 @@ func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnBackwardDirection(t *te
},
},
},
testUtils.TransactionRequest2{
testUtils.Request{
// Read the book (backwards) that was deleted (in the non-commited transaction) in another transaction.
TransactionID: 1,
TransactionID: immutable.Some(1),
Request: `query {
Book {
_key
Expand Down Expand Up @@ -341,10 +342,10 @@ func TestTxnDeletionOfRelatedDocFromNonPrimarySideForwardDirection(t *testing.T)
"address": "Manning Early Access Program (MEAP)"
}`,
},
testUtils.TransactionRequest2{
testUtils.Request{
// Delete a publisher and outside the transaction ensure it's linked
// book gets correctly unlinked too.
TransactionID: 0,
TransactionID: immutable.Some(0),
Request: `mutation {
delete_Publisher(id: "bae-8a381044-9206-51e7-8bc8-dc683d5f2523") {
_key
Expand Down Expand Up @@ -402,10 +403,10 @@ func TestTxnDeletionOfRelatedDocFromNonPrimarySideBackwardDirection(t *testing.T
"address": "Manning Early Access Program (MEAP)"
}`,
},
testUtils.TransactionRequest2{
testUtils.Request{
// Delete a publisher and outside the transaction ensure it's linked
// book gets correctly unlinked too.
TransactionID: 0,
TransactionID: immutable.Some(0),
Request: `mutation {
delete_Publisher(id: "bae-8a381044-9206-51e7-8bc8-dc683d5f2523") {
_key
Expand Down
83 changes: 48 additions & 35 deletions tests/integration/mutation/simple/delete/multi_ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,64 @@ package delete
import (
"testing"

"github.com/sourcenetwork/immutable"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/simple"
)

func TestDeletionOfMultipleDocumentUsingMultipleKeys_Success(t *testing.T) {
tests := []testUtils.RequestTestCase{

{
Description: "Simple multi-key delete mutation with one key that exists.",
Docs: map[int][]string{
0: {
`{
"name": "Shahzad",
"age": 26,
"points": 48.48,
"verified": true
}`,
},
func TestDeletionOfMultipleDocumentUsingMultipleKeysWhereOneExists(t *testing.T) {
test := testUtils.TestCase{
Description: "Simple multi-key delete mutation with one key that exists.",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type User {
name: String
age: Int
points: Float
verified: Boolean
}
`,
},
TransactionalRequests: []testUtils.TransactionRequest{
{
TransactionId: 0,
Request: `mutation {
delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d"]) {
_key
}
}`,
Results: []map[string]any{
{
"_key": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d",
},
testUtils.CreateDoc{
Doc: `{
"name": "Shahzad",
"age": 26,
"points": 48.48,
"verified": true
}`,
},
testUtils.Request{
TransactionID: immutable.Some(0),
Request: `mutation {
delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d"]) {
_key
}
}`,
Results: []map[string]any{
{
"_key": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d",
},
},
{
TransactionId: 0,
Request: `query {
User(dockeys: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d"]) {
_key
}
}`,
Results: []map[string]any{},
},
},
testUtils.Request{
TransactionID: immutable.Some(0),
Request: `query {
User(dockeys: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d"]) {
_key
}
}`,
Results: []map[string]any{},
},
},
}

testUtils.ExecuteTestCase(t, []string{"User"}, test)
}

func TestDeletionOfMultipleDocumentUsingMultipleKeys_Success(t *testing.T) {
tests := []testUtils.RequestTestCase{
{
Description: "Delete multiple documents that exist, when given multiple keys.",
Request: `mutation {
Expand Down
Loading