mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
rpc: remove sleep in TestNotifications
This commit is contained in:
parent
810455a4a3
commit
ded0002e31
1 changed files with 13 additions and 23 deletions
|
|
@ -27,9 +27,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type NotificationTestService struct {
|
type NotificationTestService struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
unsubscribed bool
|
unsubscribed chan string
|
||||||
|
|
||||||
gotHangSubscriptionReq chan struct{}
|
gotHangSubscriptionReq chan struct{}
|
||||||
unblockHangSubscription chan struct{}
|
unblockHangSubscription chan struct{}
|
||||||
}
|
}
|
||||||
|
|
@ -38,16 +37,10 @@ func (s *NotificationTestService) Echo(i int) int {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NotificationTestService) wasUnsubCallbackCalled() bool {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
return s.unsubscribed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *NotificationTestService) Unsubscribe(subid string) {
|
func (s *NotificationTestService) Unsubscribe(subid string) {
|
||||||
s.mu.Lock()
|
if s.unsubscribed != nil {
|
||||||
s.unsubscribed = true
|
s.unsubscribed <- subid
|
||||||
s.mu.Unlock()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *NotificationTestService) SomeSubscription(ctx context.Context, n, val int) (*Subscription, error) {
|
func (s *NotificationTestService) SomeSubscription(ctx context.Context, n, val int) (*Subscription, error) {
|
||||||
|
|
@ -73,13 +66,10 @@ func (s *NotificationTestService) SomeSubscription(ctx context.Context, n, val i
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-notifier.Closed():
|
case <-notifier.Closed():
|
||||||
s.mu.Lock()
|
|
||||||
s.unsubscribed = true
|
|
||||||
s.mu.Unlock()
|
|
||||||
case <-subscription.Err():
|
case <-subscription.Err():
|
||||||
s.mu.Lock()
|
}
|
||||||
s.unsubscribed = true
|
if s.unsubscribed != nil {
|
||||||
s.mu.Unlock()
|
s.unsubscribed <- string(subscription.ID)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -106,7 +96,7 @@ func (s *NotificationTestService) HangSubscription(ctx context.Context, val int)
|
||||||
|
|
||||||
func TestNotifications(t *testing.T) {
|
func TestNotifications(t *testing.T) {
|
||||||
server := NewServer()
|
server := NewServer()
|
||||||
service := &NotificationTestService{}
|
service := &NotificationTestService{unsubscribed: make(chan string)}
|
||||||
|
|
||||||
if err := server.RegisterName("eth", service); err != nil {
|
if err := server.RegisterName("eth", service); err != nil {
|
||||||
t.Fatalf("unable to register test service %v", err)
|
t.Fatalf("unable to register test service %v", err)
|
||||||
|
|
@ -156,10 +146,10 @@ func TestNotifications(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
clientConn.Close() // causes notification unsubscribe callback to be called
|
clientConn.Close() // causes notification unsubscribe callback to be called
|
||||||
time.Sleep(1 * time.Second)
|
select {
|
||||||
|
case <-service.unsubscribed:
|
||||||
if !service.wasUnsubCallbackCalled() {
|
case <-time.After(1 * time.Second):
|
||||||
t.Error("unsubscribe callback not called after closing connection")
|
t.Fatal("Unsubscribe not called after one second")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue