-
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.
Merge pull request #12 from piaodazhu/dev
improve test coverage && add benchmark
- Loading branch information
Showing
8 changed files
with
331 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
- [x] Hook API | ||
- [x] Unit Tests | ||
- [x] Code Report | ||
- [ ] Better Coverage | ||
- [ ] Benchmark | ||
- [x] Better Coverage | ||
- [x] Benchmark | ||
- [x] Register arguments: maxConn, maxServeNum, maxServeTime | ||
- [x] Active user status |
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 was deleted.
Oops, something went wrong.
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,37 @@ | ||
package proxylite | ||
|
||
import "testing" | ||
|
||
func TestContextNil(t *testing.T) { | ||
data := []byte{'a'} | ||
ctx := makeContext(nil, nil, data, nil) | ||
if ctx.AbortTunnel() == nil { | ||
t.Error("AbortTunnel") | ||
} | ||
if ctx.AbortUser() == nil { | ||
t.Error("AbortUser") | ||
} | ||
if ctx.DataBuffer() == nil { | ||
t.Error("DataBuffer") | ||
} | ||
|
||
blankInfo := ServiceInfo{} | ||
if ctx.ServiceInfo() != blankInfo { | ||
t.Error("ServiceInfo") | ||
} | ||
if ctx.UserLocalAddress() != nil { | ||
t.Error("UserLocalAddress") | ||
} | ||
if ctx.UserRemoteAddress() != nil { | ||
t.Error("UserRemoteAddress") | ||
} | ||
if ctx.InnerLocalConn() != nil { | ||
t.Error("InnerLocalConn") | ||
} | ||
if ctx.InnerRemoteConn() != nil { | ||
t.Error("InnerRemoteConn") | ||
} | ||
if _, ok := ctx.GetValue("k"); ok { | ||
t.Error("GetValue") | ||
} | ||
} |
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,95 @@ | ||
package proxylite | ||
|
||
import ( | ||
"net" | ||
"strings" | ||
"testing" | ||
"time" | ||
) | ||
|
||
var msg = strings.Repeat("hello", 100) | ||
|
||
func init() { | ||
if err := newTcpEchoServer(":9969", len(msg)); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func BenchmarkProxylite(b *testing.B) { | ||
proxyServer := NewProxyLiteServer() | ||
proxyServer.SetLogger(nil) | ||
proxyServer.AddPort(9968, 9968) | ||
go func() { | ||
if err := proxyServer.Run(":9967"); err != nil { | ||
panic(err) | ||
} | ||
}() | ||
time.Sleep(time.Millisecond * 10) | ||
|
||
innerClient := NewProxyLiteClient(":9967") | ||
innerClient.SetLogger(nil) | ||
|
||
cancelFunc, done, err := innerClient.RegisterInnerService( | ||
RegisterInfo{ | ||
OuterPort: 9968, | ||
InnerAddr: ":9969", | ||
Name: "Echo", | ||
Message: "TCP Echo Server", | ||
}, | ||
ControlInfo{}, | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer func() { | ||
cancelFunc() | ||
<-done | ||
proxyServer.Stop() | ||
}() | ||
time.Sleep(time.Millisecond * 10) | ||
|
||
user, err := net.Dial("tcp", ":9968") | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
|
||
b.StartTimer() | ||
for i := 0; i < b.N; i++ { | ||
err := written(user, []byte(msg), len(msg)) | ||
if err != nil { | ||
b.Error("write 1, ", err) | ||
} | ||
_, err = readn(user, len(msg)) | ||
if err != nil { | ||
b.Error("read 1, ", err) | ||
} | ||
} | ||
b.StopTimer() | ||
user.Close() | ||
time.Sleep(time.Millisecond * 100) | ||
select { | ||
case <-done: | ||
b.Error("unexpected quit") | ||
default: | ||
} | ||
} | ||
|
||
func BenchmarkNoProxy(b *testing.B) { | ||
user, err := net.Dial("tcp", ":9969") | ||
if err != nil { | ||
b.Fail() | ||
} | ||
b.StartTimer() | ||
for i := 0; i < b.N; i++ { | ||
err := written(user, []byte(msg), len(msg)) | ||
if err != nil { | ||
b.Error("write 1, ", err) | ||
} | ||
_, err = readn(user, len(msg)) | ||
if err != nil { | ||
b.Error("read 1, ", err) | ||
} | ||
} | ||
b.StopTimer() | ||
user.Close() | ||
} |
Oops, something went wrong.