-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Infinite loop when updating one-one relation (#1915)
## Relevant issue(s) Resolves #1914 ## Description Fixes an a bug where an infinite loop may be created when updating a self-referencing one-one relation from the secondary side.
- Loading branch information
1 parent
2c862ac
commit e952be5
Showing
5 changed files
with
218 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
tests/integration/mutation/update/field_kinds/one_to_one/with_self_ref_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
// Copyright 2023 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package one_to_one | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestMutationUpdateOneToOne_SelfReferencingFromPrimary(t *testing.T) { | ||
user1ID := "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" | ||
|
||
test := testUtils.TestCase{ | ||
Description: "One to one update mutation, self referencing from primary", | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type User { | ||
name: String | ||
boss: User @primary | ||
underling: User | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "John" | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "Fred" | ||
}`, | ||
}, | ||
testUtils.UpdateDoc{ | ||
DocID: 1, | ||
Doc: fmt.Sprintf( | ||
`{ | ||
"boss_id": "%s" | ||
}`, | ||
user1ID, | ||
), | ||
}, | ||
testUtils.Request{ | ||
Request: ` | ||
query { | ||
User { | ||
name | ||
boss { | ||
name | ||
} | ||
} | ||
}`, | ||
Results: []map[string]any{ | ||
{ | ||
"name": "Fred", | ||
"boss": map[string]any{ | ||
"name": "John", | ||
}, | ||
}, | ||
{ | ||
"name": "John", | ||
"boss": nil, | ||
}, | ||
}, | ||
}, | ||
testUtils.Request{ | ||
Request: ` | ||
query { | ||
User { | ||
name | ||
underling { | ||
name | ||
} | ||
} | ||
}`, | ||
Results: []map[string]any{ | ||
{ | ||
"name": "Fred", | ||
"underling": nil, | ||
}, | ||
{ | ||
"name": "John", | ||
"underling": map[string]any{ | ||
"name": "Fred", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestMutationUpdateOneToOne_SelfReferencingFromSecondary(t *testing.T) { | ||
user1ID := "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" | ||
|
||
test := testUtils.TestCase{ | ||
Description: "One to one update mutation, self referencing from secondary", | ||
|
||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type User { | ||
name: String | ||
boss: User | ||
underling: User @primary | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "John" | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "Fred" | ||
}`, | ||
}, | ||
testUtils.UpdateDoc{ | ||
DocID: 1, | ||
Doc: fmt.Sprintf( | ||
`{ | ||
"boss_id": "%s" | ||
}`, | ||
user1ID, | ||
), | ||
}, | ||
testUtils.Request{ | ||
Request: ` | ||
query { | ||
User { | ||
name | ||
boss { | ||
name | ||
} | ||
} | ||
}`, | ||
Results: []map[string]any{ | ||
{ | ||
"name": "Fred", | ||
"boss": map[string]any{ | ||
"name": "John", | ||
}, | ||
}, | ||
{ | ||
"name": "John", | ||
"boss": nil, | ||
}, | ||
}, | ||
}, | ||
testUtils.Request{ | ||
Request: ` | ||
query { | ||
User { | ||
name | ||
underling { | ||
name | ||
} | ||
} | ||
}`, | ||
Results: []map[string]any{ | ||
{ | ||
"name": "Fred", | ||
"underling": nil, | ||
}, | ||
{ | ||
"name": "John", | ||
"underling": map[string]any{ | ||
"name": "Fred", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |