Added good integration tests for PingRequest addition

This commit is contained in:
Simeng He
2021-05-21 12:04:04 -04:00
parent a374db1f8b
commit 8cf74ee5e3
2 changed files with 23 additions and 7 deletions

View File

@@ -784,9 +784,24 @@ func TestControlSelectivePing(t *testing.T) {
n1.AwaitRunning(t)
n2.AwaitRunning(t)
t.Log("CONTROLURL", env.ControlServer.URL)
req := new(tailcfg.MapRequest)
req.Ping = true
t.Log("NEWREQ", req)
env.Control.MapResponse(req)
if err := tstest.WaitFor(2*time.Second, func() error {
st := n1.MustStatus(t)
req.NodeKey = tailcfg.NodeKey(st.Self.PublicKey)
return nil
}); err != nil {
t.Error(err)
}
mr, err := env.Control.MapResponse(req)
if err != nil {
t.Error(err)
}
t.Log("RECEIVED PR", mr.PingRequest)
if mr.PingRequest == nil {
t.Error("PingRequest does not exist")
}
d1.MustCleanShutdown(t)
d2.MustCleanShutdown(t)
}

View File

@@ -570,11 +570,12 @@ func (s *Server) MapResponse(req *tailcfg.MapRequest) (res *tailcfg.MapResponse,
res.Node.AllowedIPs = res.Node.Addresses
// Function to add a PingRequest to one of its Peers to the MapResponse
err = s.addPingRequest(res)
if err != nil {
log.Println("ADDPINGREQ ERROR", err)
if req.Ping {
err = s.addPingRequest(res)
if err != nil {
log.Println("ADDPINGREQ ERROR", err)
}
}
return res, nil
}