Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
getty
Commits
2d033a8e
Commit
2d033a8e
authored
Mar 02, 2020
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add: ut
parent
a733de85
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
500 additions
and
0 deletions
+500
-0
client_test.go
client_test.go
+392
-0
server_test.go
server_test.go
+108
-0
No files found.
client_test.go
0 → 100644
View file @
2d033a8e
This diff is collapsed.
Click to expand it.
server_test.go
0 → 100644
View file @
2d033a8e
package
getty
import
(
"testing"
"time"
)
import
(
"github.com/stretchr/testify/assert"
)
func
TestTCPServer
(
t
*
testing
.
T
)
{
var
(
server
*
server
serverMsgHandler
MessageHandler
)
addr
:=
"127.0.0.1:0"
func
()
{
server
=
newServer
(
TCP_SERVER
,
WithLocalAddress
(
addr
),
)
newServerSession
:=
func
(
session
Session
)
error
{
return
newSessionCallback
(
session
,
&
serverMsgHandler
)
}
server
.
RunEventLoop
(
newServerSession
)
assert
.
True
(
t
,
server
.
ID
()
>
0
)
assert
.
True
(
t
,
server
.
EndPointType
()
==
TCP_SERVER
)
}()
time
.
Sleep
(
500e6
)
addr
=
server
.
streamListener
.
Addr
()
.
String
()
t
.
Logf
(
"server addr: %v"
,
addr
)
clt
:=
newClient
(
TCP_CLIENT
,
WithServerAddress
(
addr
),
WithReconnectInterval
(
5e8
),
WithConnectionNumber
(
1
),
)
assert
.
NotNil
(
t
,
clt
)
assert
.
True
(
t
,
clt
.
ID
()
>
0
)
assert
.
Equal
(
t
,
clt
.
endPointType
,
TCP_CLIENT
)
var
(
msgHandler
MessageHandler
)
cb
:=
func
(
session
Session
)
error
{
return
newSessionCallback
(
session
,
&
msgHandler
)
}
clt
.
RunEventLoop
(
cb
)
time
.
Sleep
(
1e9
)
assert
.
Equal
(
t
,
1
,
msgHandler
.
SessionNumber
())
clt
.
Close
()
assert
.
True
(
t
,
clt
.
IsClosed
())
server
.
Close
()
assert
.
True
(
t
,
server
.
IsClosed
())
}
func
TestUDPServer
(
t
*
testing
.
T
)
{
var
(
server
*
server
serverMsgHandler
MessageHandler
)
addr
:=
"127.0.0.1:0"
func
()
{
server
=
newServer
(
UDP_ENDPOINT
,
WithLocalAddress
(
addr
),
)
newServerSession
:=
func
(
session
Session
)
error
{
return
newSessionCallback
(
session
,
&
serverMsgHandler
)
}
server
.
RunEventLoop
(
newServerSession
)
assert
.
True
(
t
,
server
.
ID
()
>
0
)
assert
.
True
(
t
,
server
.
EndPointType
()
==
UDP_ENDPOINT
)
}()
time
.
Sleep
(
500e6
)
//addr = server.streamListener.Addr().String()
//t.Logf("server addr: %v", addr)
//clt := newClient(TCP_CLIENT,
// WithServerAddress(addr),
// WithReconnectInterval(5e8),
// WithConnectionNumber(1),
//)
//assert.NotNil(t, clt)
//assert.True(t, clt.ID() > 0)
//assert.Equal(t, clt.endPointType, TCP_CLIENT)
//
//var (
// msgHandler MessageHandler
//)
//cb := func(session Session) error {
// return newSessionCallback(session, &msgHandler)
//}
//
//clt.RunEventLoop(cb)
//time.Sleep(1e9)
//
//assert.Equal(t, 1, msgHandler.SessionNumber())
//clt.Close()
//assert.True(t, clt.IsClosed())
//
//server.Close()
//assert.True(t, server.IsClosed())
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment