tianxiaoliang commented on a change in pull request #114: URL: https://github.com/apache/servicecomb-mesher/pull/114#discussion_r411911607
########## File path: proxy/protocol/dubbo/utils/msgqueue_test.go ########## @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package util + +import ( + "container/list" + "github.com/stretchr/testify/assert" + "sync" + "testing" + "time" +) + +func NewMsgQueueForTest(maxMsgNum int) *MsgQueue { + q := new(MsgQueue) + q.msgList = list.New() + q.mtx = new(sync.Mutex) + q.msgCount = 0 + q.maxMsgNum = maxMsgNum + q.state = Actived + q.notEmptyCond = sync.NewCond(q.mtx) + q.notFullCond = sync.NewCond(q.mtx) + return q +} + +func TestMsgQueue(t *testing.T) { + t.Run("case empty", func(t *testing.T) { + q := NewMsgQueueForTest(2) + + // append msg + eMSG := "msg to send" + err := q.Enqueue(eMSG) + assert.NoError(t, err) + + assert.Equal(t, false, q.isEmpty()) + assert.Equal(t, false, q.isFull()) + + // pop msg + dMSG, err := q.Dequeue() + assert.NoError(t, err) + assert.Equal(t, eMSG, dMSG) + + // case empty + go func() { + dMSG, err = q.Dequeue() + assert.NoError(t, err) + + // Deavtive + q.Deavtive() + + // error + _, err = q.Dequeue() + assert.Error(t, err) + }() + + select { + case <-time.After(time.Second * 10): Review comment: 不要这样让开调度 有个专门用来让开协程调度的方法,大概叫什么sched ########## File path: proxy/protocol/dubbo/utils/thrmgr_test.go ########## @@ -0,0 +1,44 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. + */ + +package util + +import ( + "github.com/stretchr/testify/assert" + "testing" + "time" +) + +func TestNewThreadGroupWait(t *testing.T) { + count := 0 + go func() { + var tgw *ThreadGroupWait + tgw = NewThreadGroupWait() + tgw.Add(1) + go func(tgw *ThreadGroupWait) { + defer tgw.Done() + count++ + }(tgw) + tgw.Wait() + }() + + select { + case <-time.After(time.Second * 2): Review comment: 一样,不要去写死等待时间 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org