Closed SergeyRadist closed 4 years ago
Hi @SergeyRadist Thanks for posting the issue!
I briefly looked at your test and it seems like these tests are completely isolated one from each other so as mocks.
The difference between Set and Inspect is that all the code inside the Set(ted) func is executed when the test is running while inspect is called when the test is done and mc.Finish() is called. So my guess is that you either have race somewhere in your code or somewhere in the test. For example if you have following in every test:
opened = []record.CompositeFilamentRecord{
// req that we closing
{
RecordID: requestID,
Record: record.Material{
Virtual: record.Wrap(&record.OutgoingRequest{}),
},
},
}
Where opened is some local variable so if mocked OpenedRequests method is being called concurrently somewhere you have a data race. Of course wrapping the call to mocked func with mutex helps in this case but what should be actually protected with mutex is a critical section where you reassign a new value to opened var. I'm sure that we don't want to protect calls to mocked methods with mutexes bc it might hide some existing race conditions in the tested code.
Please check if my above guess about opened var is right and if not please provide the generated mock file so I have more information for analysis.
@SergeyRadist did you have a chance to look at the test and wrap assignment to opened var with mutex?
@SergeyRadist did you have a chance to look at the test and wrap assignment to opened var with mutex?
Thank you very much for your advice, but unfortunately I haven't check everything yet. Planning to do it till the end of the week
Hello again and thanks!
I found a problem, in one of tests there were an invisible bug
sender := bus.NewSenderMock(t)
Only sad thing is that stack trace was unusable in this situation and I had to bother you
Btw as I can see from mock, there is no such difference between Set and Inspect. Inspected func is calling during the test and even earlier that Setted
@SergeyRadist
Ok no problem, indeed Inspect
is being called before.
Sorry for the misinformation I was looking at
func (m *{{$mock}}) MinimockFinish() {
if !m.minimockDone() {
{{- range $method := $.Interface.Methods }}
m.Minimock{{$method.Name}}Inspect()
{{ end -}}
m.t.FailNow()
}
}
But I forgot that we call inspectFunc from the mocked method.
Hello guys, I probably have race in generated _mock file. This is my test https://pastebin.com/Bt5XAxhb
go test ./ledger/light/proc/set_result_test.go -race -count 10000
full output here https://pastebin.com/EVUPkiVs short output:What I did? I've noticed that if I'm using Inspect instead of Set there is no race. So I added lock/unlock in mocked method before "Setted" func is calling and it helps
I'm not sure that it is the right solution. If so, I can make a pr
Added: I've replaced code inside function to sleep to exclude races inside it
minimock version 2.1.9 Thanks!