diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b24967d..8f1bc2e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,11 @@ - + + + + + - - - + + + + + + + + + + + + + + + + @@ -45,6 +62,10 @@ timeout cha failed channel + time.a + sleep + time.se + eventSer GrpcCommandHandlers @@ -77,12 +98,12 @@ @@ -113,6 +134,11 @@ + + + + + @@ -152,7 +178,7 @@ - + @@ -215,8 +241,8 @@ - + @@ -224,9 +250,6 @@ - - - @@ -254,6 +277,9 @@ + + + @@ -263,11 +289,12 @@ + - + - + @@ -276,7 +303,6 @@ - @@ -499,36 +525,36 @@ - + + + + - - + + - + - - + + - + - - + + - + - - + + - - - \ No newline at end of file diff --git a/mock/event_service.go b/mock/event_service.go index c2c0274..12116bd 100644 --- a/mock/event_service.go +++ b/mock/event_service.go @@ -19,6 +19,7 @@ package mock import ( "errors" "reflect" + "time" ) var ErrEventType = errors.New("Error type of event is not struct") @@ -26,17 +27,20 @@ var ErrEventType = errors.New("Error type of event is not struct") type EventService struct { ProcessId string PublishFunc func(processId string, topic string, event interface{}) error + delayTime time.Duration } func NewEventService(processId string, publishFunc func(processId string, topic string, event interface{}) error) *EventService { return &EventService{ ProcessId: processId, PublishFunc: publishFunc, + delayTime: 0, } } func (s *EventService) Publish(topic string, event interface{}) error { + time.Sleep(s.delayTime) if !eventIsStruct(event) { return ErrEventType } @@ -48,7 +52,11 @@ func (s *EventService) Publish(topic string, event interface{}) error { return nil } -func (s *EventService) Close(){} +func (s *EventService) SetDelayTime(t time.Duration) { + s.delayTime = t +} + +func (s *EventService) Close() {} func eventIsStruct(event interface{}) bool { return reflect.TypeOf(event).Kind() == reflect.Struct diff --git a/mock/event_service_test.go b/mock/event_service_test.go index 9c338be..180e345 100644 --- a/mock/event_service_test.go +++ b/mock/event_service_test.go @@ -18,18 +18,22 @@ package mock_test import ( "testing" + "time" + "github.com/it-chain/avengers/mock" "github.com/it-chain/engine/common/command" ) func TestEventService_Publish(t *testing.T) { - eventService:=mock.NewEventService("1", func(processId string, topic string, event interface{}) error { + eventService := mock.NewEventService("1", func(processId string, topic string, event interface{}) error { return nil }) + eventService.SetDelayTime(5 * time.Millisecond) + event := command.DeliverGrpc{ - MessageId:"1", + MessageId: "1", } - eventService.Publish("message.deliver",event) + eventService.Publish("message.deliver", event) } diff --git a/mock/rpc_test.go b/mock/rpc_test.go deleted file mode 100644 index 612e67c..0000000 --- a/mock/rpc_test.go +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2018 It-chain - * - * Licensed 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 - * - * https://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 mock