-
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.
- Loading branch information
Showing
7 changed files
with
341 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ import ( | |
"net/http" | ||
) | ||
|
||
//annotation:user_management-service | ||
//annotation:test-service | ||
//author:{"name":"user_management","tel":"15521212871","email":"[email protected]"} | ||
func Enroll(author string) { | ||
var developer *cmn.ModuleAuthor | ||
|
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,20 +3,19 @@ | |
package service | ||
|
||
import ( | ||
|
||
"chatroom/serve/file_management" //file_management , file_management, 15521212871, [email protected] | ||
"chatroom/serve/login" //login , login, 15521212871, [email protected] | ||
"chatroom/serve/register" //register , register, 15521212871, [email protected] | ||
"chatroom/serve/test" //user_management , user_management, 15521212871, [email protected] | ||
"chatroom/serve/login" //login , login, 15521212871, [email protected] | ||
"chatroom/serve/register" //register , register, 15521212871, [email protected] | ||
"chatroom/serve/test" //test , user_management, 15521212871, [email protected] | ||
"chatroom/serve/user_management" //user_management , user_management, 15521212871, [email protected] | ||
) | ||
|
||
//Enroll will be called from serve cmd | ||
func Enroll(){ | ||
file_management.Enroll(`{"name":"file_management","tel":"15521212871","email":"[email protected]"}`) | ||
login.Enroll(`{"name":"login","tel":"15521212871","email":"[email protected]"}`) | ||
register.Enroll(`{"name":"register","tel":"15521212871","email":"[email protected]"}`) | ||
test.Enroll(`{"name":"user_management","tel":"15521212871","email":"[email protected]"}`) | ||
user_management.Enroll(`{"name":"user_management","tel":"15521212871","email":"[email protected]"}`) | ||
func Enroll() { | ||
|
||
file_management.Enroll(`{"name":"file_management","tel":"15521212871","email":"[email protected]"}`) | ||
login.Enroll(`{"name":"login","tel":"15521212871","email":"[email protected]"}`) | ||
register.Enroll(`{"name":"register","tel":"15521212871","email":"[email protected]"}`) | ||
test.Enroll(`{"name":"user_management","tel":"15521212871","email":"[email protected]"}`) | ||
user_management.Enroll(`{"name":"user_management","tel":"15521212871","email":"[email protected]"}`) | ||
} |
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,125 @@ | ||
package test | ||
|
||
import ( | ||
"chatroom/serve" | ||
"fmt" | ||
"github.com/gorilla/websocket" | ||
"log" | ||
"sync" | ||
"sync/atomic" | ||
"testing" | ||
"time" | ||
) | ||
|
||
var ( | ||
url = "ws://localhost:8082/chat" | ||
start = make(chan struct{}) | ||
// 计数 | ||
done int32 | ||
// 每个连接发送的信息数量 = msgNums + 1 | ||
msgNums = 2000 | ||
wg sync.WaitGroup | ||
//end = false | ||
) | ||
var d1 = serve.UserInfo{Password: "123", Username: "u1"} | ||
var d2 = serve.UserInfo{Password: "123", Username: "a"} | ||
var user1 = serve.BroadcastData{Type: "login", Data: d1} | ||
var user2 = serve.BroadcastData{Type: "login", Data: d2} | ||
|
||
var m1 = serve.Message{From: 1, To: 7, Context: "i'm 1"} | ||
var m2 = serve.Message{From: 7, To: 1, Context: "i'm 7"} | ||
|
||
var msg1 = serve.BroadcastData{Type: "msg", Data: m1} | ||
var msg2 = serve.BroadcastData{Type: "msg", Data: m2} | ||
|
||
func Worker(id int) { | ||
end := false | ||
|
||
ws, _, err := websocket.DefaultDialer.Dial(url, nil) | ||
if err != nil { | ||
log.Println("worker ", id, " dial fail:", err) | ||
return | ||
} | ||
t := time.NewTicker(3 * time.Second) | ||
go func() { | ||
select { | ||
case <-t.C: | ||
end = true | ||
return | ||
} | ||
}() | ||
if id == 1 { | ||
ws.WriteJSON(user1) | ||
println("u1 login") | ||
} else { | ||
ws.WriteJSON(user2) | ||
println("u2 login") | ||
} | ||
// 等待开始 | ||
<-start | ||
|
||
send := 0 | ||
|
||
defer func() { | ||
ws.Close() | ||
log.Printf("worker %3d done, send:%3d \n", id, send) | ||
wg.Done() | ||
}() | ||
for { | ||
//msg := []byte("{\"msg\":\"worker " + strconv.Itoa(id) + "\"}") | ||
if id == 1 { | ||
err = ws.WriteJSON(msg1) | ||
} else { | ||
err = ws.WriteJSON(msg2) | ||
} | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
send++ | ||
if end { | ||
atomic.AddInt32(&done, 1) | ||
return | ||
} | ||
//var buf []byte | ||
//_, buf, err := ws.ReadMessage() | ||
//if err != nil { | ||
// log.Fatal("read wrong", id) | ||
// return | ||
//} | ||
//var a interface{} | ||
//json.Unmarshal(buf, a) | ||
//println(a) | ||
|
||
// 自定义数量 | ||
|
||
//if send > msgNums { | ||
// // 结束全部任务 | ||
// atomic.AddInt32(&done, 1) | ||
// return | ||
//} | ||
|
||
//time.Sleep(time.Second) | ||
} | ||
} | ||
|
||
func Test_A(t *testing.T) { | ||
// 建立连接 | ||
//循环次数就是连接的数量 | ||
//for i := range [70][0]int{} { | ||
// go Worker(i) | ||
// wg.Add(1) | ||
//} | ||
// 开始发送 | ||
go Worker(1) | ||
wg.Add(1) | ||
go Worker(2) | ||
wg.Add(1) | ||
close(start) | ||
// 等待发送任务完成 | ||
wg.Wait() | ||
|
||
// 打印完成结果 | ||
log.Println("done:", done) | ||
|
||
fmt.Println("程序测试完成") | ||
} |
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,92 @@ | ||
package test | ||
|
||
// | ||
//import ( | ||
// "chatroom/serve" | ||
// "encoding/json" | ||
// "github.com/gorilla/websocket" | ||
// "log" | ||
// "testing" | ||
//) | ||
// | ||
////var( | ||
//// user1 serve.BroadcastData | ||
//// user2 serve.BroadcastData | ||
//// msg1 serve.BroadcastData | ||
//// msg2 serve.BroadcastData | ||
////) | ||
//var d1 = serve.UserInfo{Password: "123", Username: "u1"} | ||
//var d2 = serve.UserInfo{Password: "123", Username: "a"} | ||
// | ||
////var buf1, _ = json.Marshal(d1) | ||
////var buf2, _ = json.Marshal(d2) | ||
//var user1 = serve.BroadcastData{Type: "login", Data: d1} | ||
//var user2 = serve.BroadcastData{Type: "login", Data: d2} | ||
// | ||
//var m1 = serve.Message{From: 1, To: 7, Context: "i'm 1"} | ||
//var m2 = serve.Message{From: 7, To: 1, Context: "i'm 7"} | ||
//var buf3, _ = json.Marshal(m1) | ||
//var buf4, _ = json.Marshal(m2) | ||
//var msg1 = serve.BroadcastData{Type: "msg", Data: buf3} | ||
//var msg2 = serve.BroadcastData{Type: "msg", Data: buf4} | ||
// | ||
////建立新的连接 | ||
//func newWSServer() *websocket.Conn { | ||
// //b.Helper() | ||
// url := "ws://localhost:8082/chat" | ||
// ws, _, err := websocket.DefaultDialer.Dial(url, nil) | ||
// if err != nil { | ||
// //b.Error(err) | ||
// //b.Failed() | ||
// log.Println(err) | ||
// return nil | ||
// } | ||
// //b.ReportAllocs() | ||
// log.Println("ws connect") | ||
// return ws | ||
//} | ||
// | ||
//func sendMessage(b *testing.B, conn *websocket.Conn, data serve.BroadcastData) { | ||
// b.Helper() | ||
// buf, err := json.Marshal(data) | ||
// if err != nil { | ||
// b.Fatal(err) | ||
// } | ||
// err = conn.WriteJSON(buf) | ||
// if err != nil { | ||
// b.Fatal(err) | ||
// } | ||
//} | ||
// | ||
//func receiveMessage(b *testing.B, conn *websocket.Conn) { | ||
// b.Helper() | ||
// _, _, err := conn.ReadMessage() | ||
// if err != nil { | ||
// b.Fatal(err) | ||
// } | ||
// | ||
//} | ||
// | ||
//var count = 0 | ||
// | ||
//func BenchmarkChat(b *testing.B) { | ||
// | ||
// //b.N = 2 | ||
// //if count == 0 { | ||
// //conn1 := newWSServer() | ||
// //conn2 := newWSServer() | ||
// newWSServer() | ||
// //} | ||
// //count++ | ||
// b.StopTimer() | ||
// //sendMessage(b, conn1, user1) | ||
// //sendMessage(b, conn2, user2) | ||
// b.StartTimer() | ||
// b.ReportAllocs() | ||
// //b.N = 2000 | ||
// //for i := 0; i < b.N; i++ { | ||
// // | ||
// //} | ||
// //defer conn1.Close() | ||
// //defer conn2.Close() | ||
//} |
Oops, something went wrong.