agent: Leave should wait for the agent to stop accepting assignments
agent: Leave should wait for the agent to stop accepting assignments

A data race is possible when the agent leaves the cluster. Leave calls
Wait, but Wait may race with starting a new worker when an assignment is
accepted. The existing code signals to the agent's main loop to stop
accepting assignments, but this isn't quite enough because an assignment
may be received at the same time as this signal. Wait for the main loop
to stop accepting assingments before calling Wait.

Signed-off-by: Aaron Lehmann <8ecfc6017a87905413dcd7d63696a2a4c351b604@docker.com>

alyyousuf7/swarmkit,cheyang/swarmkit,sungwonh/swarmkit,alyyousuf7/swarmkit,RenaudWasTaken/swarmkit,RenaudWasTaken/swarmkit,yongtang/swarmkit,elifa/swarmkit,Noyan759/swarmkit,deljuven/swarmkit,allencloud/swarmkit,docker/swarmkit,jlhawn/swarmkit,yongtang/swarmkit,AliyunContainerService/swarmkit,fate-grand-order/swarmkit,elifa/swarmkit,sungwonh/swarmkit,docker/swarmkit,dperny/swarmkit-1,diogomonica/swarmkit,fate-grand-order/swarmkit,dperny/swarmkit-1,AliyunContainerService/swarmkit,cheyang/swarmkit,jlhawn/swarmkit,allencloud/swarmkit,Noyan759/swarmkit,deljuven/swarmkit,diogomonica/swarmkit