Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
621e7c23
Commit
621e7c23
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
finish fixing unit tests
parent
3ed30645
Branches
Branches containing commit
Tags
Tags containing commit
3 merge requests
!60
Revert "Fail a test to be sure it works"
,
!36
project/DM
,
!32
Admin Commands
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
indexedDb/channels/implementation.go
+5
-1
5 additions, 1 deletion
indexedDb/channels/implementation.go
indexedDb/channels/implementation_test.go
+20
-11
20 additions, 11 deletions
indexedDb/channels/implementation_test.go
with
25 additions
and
12 deletions
indexedDb/channels/implementation.go
+
5
−
1
View file @
621e7c23
...
...
@@ -13,6 +13,7 @@ import (
"crypto/ed25519"
"encoding/base64"
"encoding/json"
"strings"
"sync"
"syscall/js"
"time"
...
...
@@ -423,7 +424,10 @@ func (w *wasmModel) receiveHelper(newMessage *Message, isUpdate bool) (uint64,
// Store message to database
result
,
err
:=
indexedDb
.
Put
(
w
.
db
,
messageStoreName
,
messageObj
)
if
err
!=
nil
{
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
"at least one key does not satisfy the uniqueness requirements"
)
{
// Only return non-unique constraint errors so that the case
// below this one can be hit and handle duplicate entries properly.
return
0
,
errors
.
Errorf
(
"Unable to put Message: %+v"
,
err
)
}
...
...
This diff is collapsed.
Click to expand it.
indexedDb/channels/implementation_test.go
+
20
−
11
View file @
621e7c23
...
...
@@ -446,15 +446,18 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
testMsg
:=
buildMessage
([]
byte
(
testString
),
testMsgId
.
Bytes
(),
nil
,
testString
,
[]
byte
(
testString
),
[]
byte
{
8
,
6
,
7
,
5
},
0
,
0
,
netTime
.
Now
(),
time
.
Second
,
0
,
0
,
false
,
false
,
channels
.
Sent
)
_
,
err
=
eventModel
.
receiveHelper
(
testMsg
,
false
)
uuid
,
err
:
=
eventModel
.
receiveHelper
(
testMsg
,
false
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// The duplicate entry should fail
_
,
err
=
eventModel
.
receiveHelper
(
testMsg
,
false
)
if
err
==
nil
{
t
.
Fatalf
(
"Expected duplicate insert to fail!"
)
// The duplicate entry should return the same UUID
duplicateUuid
,
err
:=
eventModel
.
receiveHelper
(
testMsg
,
false
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
uuid
!=
duplicateUuid
{
t
.
Fatalf
(
"Expected UUID %d to match %d"
,
uuid
,
duplicateUuid
)
}
// Now insert a message with a different message ID from the first
...
...
@@ -462,18 +465,24 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
testMsg
=
buildMessage
([]
byte
(
testString
),
testMsgId2
.
Bytes
(),
nil
,
testString
,
[]
byte
(
testString
),
[]
byte
{
8
,
6
,
7
,
5
},
0
,
0
,
netTime
.
Now
(),
time
.
Second
,
0
,
0
,
false
,
false
,
channels
.
Sent
)
primaryKey
,
err
:=
eventModel
.
receiveHelper
(
testMsg
,
false
)
uuid2
,
err
:=
eventModel
.
receiveHelper
(
testMsg
,
false
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
uuid2
==
uuid
{
t
.
Fatalf
(
"Expected UUID %d to NOT match %d"
,
uuid
,
duplicateUuid
)
}
// Except this time, we update the second entry to have the same
// message ID as the first
, which needs to fail
testMsg
.
ID
=
primaryKey
// message ID as the first
testMsg
.
ID
=
uuid
testMsg
.
MessageID
=
testMsgId
.
Bytes
()
_
,
err
=
eventModel
.
receiveHelper
(
testMsg
,
true
)
if
err
==
nil
{
t
.
Fatal
(
"Expected duplicate update to fail!"
)
duplicateUuid2
,
err
:=
eventModel
.
receiveHelper
(
testMsg
,
true
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
duplicateUuid2
!=
duplicateUuid
{
t
.
Fatalf
(
"Expected UUID %d to match %d"
,
uuid
,
duplicateUuid
)
}
})
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment