forked from dustin/go-coap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. changed examples to use this package 2. response timeout issue is recorded in original repo at dustin#43
- Loading branch information
Sergei G
committed
Jun 6, 2017
1 parent
753e896
commit 4ac9ea7
Showing
8 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package coap_test | ||
|
||
import ( | ||
"testing" | ||
|
||
coap "github.com/Kulak/go-coap" | ||
|
||
"time" | ||
|
||
"math" | ||
) | ||
|
||
func TestTimeoutDefaults(t *testing.T) { | ||
testTimeout(t, coap.DefaultResponseTimeout) | ||
} | ||
|
||
func TestTimeout6sec(t *testing.T) { | ||
testTimeout(t, 6*time.Second) | ||
} | ||
|
||
func testTimeout(t *testing.T, expectedTimeout time.Duration) { | ||
// send to IP address without CoAP EP | ||
req := coap.Message{ | ||
Type: coap.Confirmable, | ||
Code: coap.GET, | ||
MessageID: 12345, | ||
Payload: []byte("undeliverable"), | ||
} | ||
req.SetOption(coap.MaxAge, 3) | ||
req.SetPathString("/some/path") | ||
|
||
c, err := coap.DialWithTimeout("udp", "192.168.254.254:5683", expectedTimeout) | ||
if err != nil { | ||
t.Errorf("Error dialing: %v", err) | ||
return | ||
} | ||
|
||
start := time.Now() | ||
_, err = c.Send(req) | ||
end := time.Now() | ||
timeout := end.Sub(start) | ||
if err != nil { | ||
// that's not going to get printed unless test fails | ||
t.Logf("Error sending request: %v", err) | ||
if math.Abs(timeout.Seconds()-expectedTimeout.Seconds()) > 0.1 { | ||
t.Fatalf("Expected timeout %v, got %v", expectedTimeout, timeout) | ||
} | ||
return | ||
} | ||
t.Fatal("Response shall timeout.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ package main | |
import ( | ||
"log" | ||
|
||
"github.com/dustin/go-coap" | ||
"github.com/Kulak/go-coap" | ||
) | ||
|
||
func main() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ package main | |
import ( | ||
"log" | ||
|
||
"github.com/dustin/go-coap" | ||
"github.com/Kulak/go-coap" | ||
) | ||
|
||
func main() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import ( | |
"log" | ||
"net" | ||
|
||
"github.com/dustin/go-coap" | ||
"github.com/Kulak/go-coap" | ||
) | ||
|
||
func main() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters