-
Notifications
You must be signed in to change notification settings - Fork 53
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(autosharding): Mocked test help #2334
Conversation
df1de2e
to
b431edf
Compare
You can find the image built from this PR at
Built from eae2a2a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made quite a few attempts at fixing it but I've been utterly unsuccessful. Anyone has an idea on how to circumvent these errors?
The mocking mechanism used can be located here.
discard | ||
test "catchable error on add to topicMap": | ||
# Given the sequence.add function returns a CatchableError | ||
let backup = system.add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used to keep a reference to the original function, which is necessary for cleanup later.
Produces this error: Error: invalid type: 'None' for let
test "catchable error on add to topicMap": | ||
# Given the sequence.add function returns a CatchableError | ||
let backup = system.add | ||
mock(system.add): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then, this attempt at mocking produces:
Error: ambiguous identifier: 'add' -- you need a helper proc to disambiguate the following:
system.add: proc (x: var seq[T], y: sink T){.noSideEffect.}
system.add: proc (x: var string, y: string){.noSideEffect, gcsafe, locks: 0.}
system.add: proc (x: var string, y: char){.noSideEffect.}
system.add: proc (x: var seq[T], y: openArray[T]){.noSideEffect.}
system.add: proc (x: var string, y: cstring){.noSideEffect, gcsafe, locks: 0.}
Attempts
NotesAttempt 1Calling add like so doesn't match, because the expected first parameter is a type instance, not a type. Attempt 2One of the possible disambiguations shown by the compiler is the following:
When following the same pattern as above, but with a different disambiguation, the compiler doesn't complain: type
NsContentTopicSeqAdd =
proc(x: var seq[NsContentTopic], y: openArray[NsContentTopic]) {.
noSideEffect
.}
let
nsSeqAdd: NsContentTopicSeqAdd = system.add
nsSeqAddUnsafeAddr = unsafeAddr(nsSeqAdd)
echo repr(nsSeqAdd) # [Field0 = 0x55dc4e228490, Field1 = nil]
echo repr(nsSeqAddUnsafeAddr) # ptr 0x7ffc0384d030 --> [Field0 = 0x55dc4e228490, Field1 = nil] I've also tried running |
Posted question to Nim Forum: Link |
b431edf
to
6f570da
Compare
Description
Get the last test case working.
This case requires either:
system.add
function.Assuming
sytem.add
works flawlessly, which I kinda do; I thought the best way forward would be to mock the function but I haven't been successful in that task.Does anyone know how to make this whole ordeal work? I'm lacking some Nim proficiency to get know my way around it.
There are a couple of issues that I'll try to address in comments. All help is welcome :)
Changes
catchable error on topicMap.add
test case with mock