(ctx context.Context, n, val int)
| 51 | } |
| 52 | |
| 53 | func (s *NotificationTestService) SomeSubscription(ctx context.Context, n, val int) (*Subscription, error) { |
| 54 | notifier, supported := NotifierFromContext(ctx) |
| 55 | if !supported { |
| 56 | return nil, ErrNotificationsUnsupported |
| 57 | } |
| 58 | |
| 59 | // by explicitly creating an subscription we make sure that the subscription id is send back to the client |
| 60 | // before the first subscription.Notify is called. Otherwise the events might be send before the response |
| 61 | // for the eth_subscribe method. |
| 62 | subscription := notifier.CreateSubscription() |
| 63 | |
| 64 | go func() { |
| 65 | // test expects n events, if we begin sending event immediately some events |
| 66 | // will probably be dropped since the subscription ID might not be send to |
| 67 | // the client. |
| 68 | time.Sleep(5 * time.Second) |
| 69 | for i := 0; i < n; i++ { |
| 70 | if err := notifier.Notify(subscription.ID, val+i); err != nil { |
| 71 | return |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | select { |
| 76 | case <-notifier.Closed(): |
| 77 | s.mu.Lock() |
| 78 | s.unsubscribed = true |
| 79 | s.mu.Unlock() |
| 80 | case <-subscription.Err(): |
| 81 | s.mu.Lock() |
| 82 | s.unsubscribed = true |
| 83 | s.mu.Unlock() |
| 84 | } |
| 85 | }() |
| 86 | |
| 87 | return subscription, nil |
| 88 | } |
| 89 | |
| 90 | // HangSubscription blocks on s.unblockHangSubscription before |
| 91 | // sending anything. |
nothing calls this directly
no test coverage detected