Skip to content

Commit 4f774fa

Browse files
committed
add hard-coded test for login/hello - simplify the simplified stress engine more
1 parent 0876685 commit 4f774fa

File tree

20 files changed

+126056
-110
lines changed

20 files changed

+126056
-110
lines changed

StressTestCase/hello_no_login.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<TestSuite>
22
<TestSuiteName>Login</TestSuiteName>
33
<TargetHost>203.117.155.188</TargetHost>
4-
<TargetPort>9100</TargetPort>
4+
<TargetPort>19000</TargetPort>
55
<VarMap>
66
<Var name="email" isFunc="true" sendBack="true">
77
<Value>Helper_GetNextUserEmail</Value>

StressTestCase/login.xml.temp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@
5353
</Var>
5454
<Var name="SpecialMessage1">
5555
<MessageSequence>
56-
<Message type="Auth_C2S_HelloInfo" fromClient="true" wait="10s">
56+
<Message type="Auth_C2S_HelloInfo" fromClient="true" wait="1s">
57+
<Reuse reused="true">
58+
<Name>HelloInfo</Name>
59+
</Reuse>
5760
<Command>0x01</Command>
5861
<Data>
5962
<Auth_C2S_HelloInfo>

StressTestEngine/stressTestEngine.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ var DEBUG_READING_MESSAGE bool = true
9797
var DEBUG_IGNORING_MESSAGE bool = false
9898

9999
var DEBUG_WAITING bool = false
100+
var BYPASS_CONNECTION_SERVER bool = false
100101

101102
type InnerXml struct {
102103
Xml string `xml:",innerxml"`
@@ -222,6 +223,11 @@ type Data struct {
222223
}
223224
var SpecialChannel chan int
224225

226+
// do any initialize if needed
227+
func Initialize() {
228+
}
229+
230+
225231
/******************* steps in test ****************************************/
226232
func ExecuteTestSuite(addr *net.TCPAddr, testSuite *TestSuite) (TestResult){
227233
var data Data
@@ -447,6 +453,10 @@ func sendMsg(useBase bool, baseCmd byte, cmd byte, msg proto.Message, conn *net.
447453
length = length + 1
448454
}
449455

456+
if BYPASS_CONNECTION_SERVER {
457+
length = length + 8
458+
}
459+
450460
if DEBUG_SENDING_MESSAGE {
451461
TimeEncodedPrintln("sending message base length: ", length, " command / command / message: ", baseCmd, cmd, msg)
452462
}
@@ -459,7 +469,9 @@ func sendMsg(useBase bool, baseCmd byte, cmd byte, msg proto.Message, conn *net.
459469
}
460470

461471
binary.Write(buf, binary.LittleEndian, cmd)
462-
//binary.Write(buf, binary.LittleEndian, int64(0))
472+
if BYPASS_CONNECTION_SERVER {
473+
binary.Write(buf, binary.LittleEndian, int64(0))
474+
}
463475
buf.Write(data)
464476
n, err := conn.Write(buf.Bytes())
465477
if DEBUG_SENDING_MESSAGE {
@@ -564,6 +576,15 @@ func readReply(useBase bool, expBaseCmd byte, expCmd byte, expMsg proto.Message,
564576
return nil, err
565577
}
566578

579+
if BYPASS_CONNECTION_SERVER {
580+
tempBuf := make([]byte, 8)
581+
_, err = io.ReadFull(conn, tempBuf)
582+
if err != nil {
583+
return nil, err
584+
}
585+
length = length - 8
586+
}
587+
567588
var baseCmd byte
568589
if useBase {
569590
length = length - 1

StressTestEngine1_buggy/stressTestEngine_hardcode.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ var DEBUG_READING_MESSAGE bool = true
9797
var DEBUG_IGNORING_MESSAGE bool = false
9898

9999
var DEBUG_WAITING bool = false
100+
var BYPASS_CONNECTION_SERVER bool = false
100101

101102
type InnerXml struct {
102103
Xml string `xml:",innerxml"`
@@ -222,6 +223,11 @@ type Data struct {
222223
}
223224
var SpecialChannel chan int
224225

226+
// do any initialize if needed
227+
func Initialize() {
228+
}
229+
230+
225231
/******************* steps in test ****************************************/
226232
func ExecuteTestSuite(addr *net.TCPAddr, testSuite *TestSuite) (TestResult){
227233
conn, err := net.DialTCP("tcp", nil, addr)
@@ -280,11 +286,17 @@ func sendHelloMsg(conn *net.TCPConn) {
280286
log.Fatal("marchaling error: ", err)
281287
}
282288
length := int32(len(data)) + 1
289+
if BYPASS_CONNECTION_SERVER {
290+
length = length + 8
291+
}
283292

284293
buf := new(bytes.Buffer)
285294

286295
binary.Write(buf, binary.LittleEndian, length)
287296
binary.Write(buf, binary.LittleEndian, byte(C2S_HelloInfo_CMD))
297+
if BYPASS_CONNECTION_SERVER {
298+
binary.Write(buf, binary.LittleEndian, int64(0))
299+
}
288300
buf.Write(data)
289301
conn.Write(buf.Bytes())
290302
}
@@ -306,6 +318,15 @@ func readHelloReply(conn *net.TCPConn) (proto.Message, error) {
306318
return nil, err
307319
}
308320

321+
if BYPASS_CONNECTION_SERVER {
322+
tempBuf := make([]byte, 8)
323+
_, err = io.ReadFull(conn, tempBuf)
324+
if err != nil {
325+
return nil, err
326+
}
327+
length = length - 8
328+
}
329+
309330
rbuf := make([]byte, length)
310331
io.ReadFull(conn, rbuf)
311332

StressTestEngine_hardcode/stressTestEngine_hardcode.go

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ var DEBUG_READING_MESSAGE bool = true
9797
var DEBUG_IGNORING_MESSAGE bool = false
9898

9999
var DEBUG_WAITING bool = false
100+
var BYPASS_CONNECTION_SERVER bool = false
100101

101102
type InnerXml struct {
102103
Xml string `xml:",innerxml"`
@@ -222,10 +223,18 @@ type Data struct {
222223
}
223224
var SpecialChannel chan int
224225

226+
// do any initialize if needed
227+
func Initialize() {
228+
}
229+
230+
225231
/******************* steps in test ****************************************/
226232
func ExecuteTestSuite(addr *net.TCPAddr, testSuite *TestSuite) (TestResult){
227233
conn, err := net.DialTCP("tcp", nil, addr)
228-
duration, _ := time.ParseDuration("1s")
234+
if (DEBUG_SENDING_MESSAGE) {
235+
fmt.Println("TRYING TO CONNECT TO: ", addr, " PROBLEM: ", err)
236+
}
237+
duration := time.Second * 1
229238
if err != nil {
230239
return TestResult {
231240
IsCorrect: false,
@@ -282,9 +291,18 @@ func sendHelloMsg(conn *net.TCPConn) {
282291
length := int32(len(data)) + 1
283292

284293
buf := new(bytes.Buffer)
294+
if BYPASS_CONNECTION_SERVER {
295+
length = length + 8
296+
}
285297

286298
binary.Write(buf, binary.LittleEndian, length)
287299
binary.Write(buf, binary.LittleEndian, byte(C2S_HelloInfo_CMD))
300+
if BYPASS_CONNECTION_SERVER {
301+
if DEBUG_SENDING_MESSAGE {
302+
fmt.Println("After sending length + CMD, send 8 bytes for bypassing")
303+
}
304+
binary.Write(buf, binary.LittleEndian, int64(0))
305+
}
288306
buf.Write(data)
289307
conn.Write(buf.Bytes())
290308
}
@@ -293,7 +311,7 @@ func sendHelloMsg(conn *net.TCPConn) {
293311
// read a reply to a buffer based on the expected message type
294312
// return error if reply message has different type of command than expected
295313
func readHelloReply(conn *net.TCPConn) (proto.Message, error) {
296-
duration, _ := time.ParseDuration("1s")
314+
duration := time.Second *10
297315
timeNow := time.Now()
298316
err := conn.SetReadDeadline(timeNow.Add(duration))
299317
if err != nil {
@@ -302,12 +320,29 @@ func readHelloReply(conn *net.TCPConn) (proto.Message, error) {
302320
}
303321
length := int32(0)
304322
err = binary.Read(conn, binary.LittleEndian, &length)
323+
if DEBUG_READING_MESSAGE {
324+
fmt.Println("TRYING TO READ MESSAGE LENGTH => ", length, " ERROR: ", err)
325+
}
326+
305327
if err != nil {
306328
return nil, err
307329
}
308330

331+
if BYPASS_CONNECTION_SERVER {
332+
tempBuf := make([]byte, 8)
333+
_, err = io.ReadFull(conn, tempBuf)
334+
if DEBUG_READING_MESSAGE {
335+
fmt.Println("Trying to read extra 8 bytes:" , tempBuf, " PROBLEM: ", err)
336+
}
337+
338+
if err != nil {
339+
return nil, err
340+
}
341+
length = length - 8
342+
}
343+
309344
rbuf := make([]byte, length)
310-
io.ReadFull(conn, rbuf)
345+
n, err := io.ReadFull(conn, rbuf)
311346

312347
cmd := int(rbuf[0])
313348

@@ -330,7 +365,7 @@ func readHelloReply(conn *net.TCPConn) (proto.Message, error) {
330365
msg := fmt.Sprint("Server returns error: ")
331366
return res, errors.New(msg)
332367
default:
333-
log.Fatal("Unexpected CMD: ", cmd)
368+
log.Fatal("Unexpected CMD: ", cmd, "length is: ", length, " number bytes read: ", n, " error: ", err)
334369
}
335370
return nil, nil
336371

0 commit comments

Comments
 (0)