I have a test file and the file with the implementation (of an rpc server and its methods) under the same package in golang. I’m trying to write tests for the file but am getting errors that indicate the RPC definitions aren’t exported(?)
All the files are under the same package named mr.
Test file code:
func (c *Coordinator) TestRegisterWorker(b *testing.B) {
args := RegisterWorkerReq{}
reply := RegisterWorkerRes{}
ok := call("Coordinator.RegisterWorker", &args, &reply)
if ok {
if reply.WorkerId != 1 {
panic(1)
}
}
}
Code for the implementation:
func MakeCoordinator(files []string, nReduce int) *Coordinator {
c := Coordinator{}
//hardcoding nReduce to be 1
c.mapPhase = make(map[string]int, 1)
c.NReduce = nReduce
c.mapFileCount = nReduce
fmt.Println("Coordinator spun up")
// Your code here.
for _, file := range files {
c.mapPhase[file] = 0
}
c.taskIds = rand.Perm(len(c.mapPhase))
c.server()
return &c
}
func (c *Coordinator) RegisterWorker(args *RegisterWorkerReq, reply *RegisterWorkerRes) error {
id := rand.Intn(20)
for _, v := range c.mapPhase {
if id == v {
id = rand.Intn(20)
}
}
reply.WorkerId = id
reply.NReduce = c.NReduce
return nil
}
What am I doing wrong?