summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHu Jun <hujun.work@gmail.com>2020-07-14 16:44:43 -0700
committerHu Jun <hujun.work@gmail.com>2020-07-14 16:46:23 -0700
commitb1a957bdf2f63d8627e045c8dedbd00096d38ae9 (patch)
treecf4c11a9471556fe05998d80a5dfe9ad64e72dba
parent2be549b0b8d0519b40ce8f846c714ed60ec21c65 (diff)
- fix a lint error in lease.go
- fix a data race in lease_test.go Signed-off-by: Hu Jun <hujun.work@gmail.com>
-rw-r--r--dhcpv4/nclient4/lease.go2
-rw-r--r--dhcpv4/nclient4/lease_test.go16
2 files changed, 14 insertions, 4 deletions
diff --git a/dhcpv4/nclient4/lease.go b/dhcpv4/nclient4/lease.go
index 1bd77e5..838e39b 100644
--- a/dhcpv4/nclient4/lease.go
+++ b/dhcpv4/nclient4/lease.go
@@ -50,7 +50,7 @@ func (c *Client) Release(lease *Lease) error {
}
//This is to make sure use same client identification options used during
//DORA, so that DHCP server could identify the required lease
- for t, _ := range lease.IDOptions {
+ for t := range lease.IDOptions {
req.UpdateOption(
dhcpv4.OptGeneric(dhcpv4.GenericOptionCode(t),
lease.IDOptions.Get(dhcpv4.GenericOptionCode(t))),
diff --git a/dhcpv4/nclient4/lease_test.go b/dhcpv4/nclient4/lease_test.go
index 22d97e0..96dfae0 100644
--- a/dhcpv4/nclient4/lease_test.go
+++ b/dhcpv4/nclient4/lease_test.go
@@ -8,6 +8,7 @@ import (
"fmt"
"log"
"net"
+ "sync"
"testing"
"time"
@@ -41,14 +42,16 @@ type testServerLease struct {
}
type testServerLeaseList struct {
- list []*testServerLease
- clientIDOptions dhcpv4.OptionCodeList
- lastTestSvrErr error
+ list []*testServerLease
+ clientIDOptions dhcpv4.OptionCodeList
+ lastTestSvrErr error
+ lastTestSvrErrLock *sync.RWMutex
}
func newtestServerLeaseList(l dhcpv4.OptionCodeList) *testServerLeaseList {
r := &testServerLeaseList{}
r.clientIDOptions = l
+ r.lastTestSvrErrLock = &sync.RWMutex{}
return r
}
@@ -184,6 +187,8 @@ func (sll *testServerLeaseList) handle(conn net.PacketConn, peer net.Addr, m *dh
if m.OpCode != dhcpv4.OpcodeBootRequest {
log.Fatal("Not a BootRequest!")
}
+ sll.lastTestSvrErrLock.Lock()
+ defer sll.lastTestSvrErrLock.Unlock()
switch m.MessageType() {
case dhcpv4.MessageTypeDiscover, dhcpv4.MessageTypeRequest:
sll.lastTestSvrErr = sll.testLeaseDORAHandle(conn, peer, m)
@@ -243,13 +248,18 @@ func (sll *testServerLeaseList) runTest(t *testing.T) {
}
lease, err := clnt.Request(context.Background(), modList...)
+ sll.lastTestSvrErrLock.RLock()
keepgoing := chkerr(err, sll.lastTestSvrErr, l.ShouldFail, t)
+ sll.lastTestSvrErrLock.RUnlock()
if keepgoing {
err = clnt.Release(lease)
//this sleep is to make sure release is handled by server
time.Sleep(time.Second)
+ sll.lastTestSvrErrLock.RLock()
chkerr(err, sll.lastTestSvrErr, l.ShouldFail, t)
+ sll.lastTestSvrErrLock.RUnlock()
}
+
}
}