How to use ClearInterruptPlaceholderMessage method of test_helpers Package

Best Ginkgo code snippet using test_helpers.ClearInterruptPlaceholderMessage

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

fake_interrupt_handler.go

Source: fake_interrupt_handler.go Github

copy
1package test_helpers
2
3import (
4	"sync"
5
6	"github.com/onsi/ginkgo/v2/internal/interrupt_handler"
7)
8
9type FakeInterruptHandler struct {
10	triggerInterrupt chan bool
11
12	c                                  chan interface{}
13	stop                               chan interface{}
14	lock                               *sync.Mutex
15	interrupted                        bool
16	cause                              interrupt_handler.InterruptCause
17	interruptPlaceholderMessage        string
18	emittedInterruptPlaceholderMessage string
19}
20
21func NewFakeInterruptHandler() *FakeInterruptHandler {
22	handler := &FakeInterruptHandler{
23		triggerInterrupt: make(chan bool),
24		c:                make(chan interface{}),
25		lock:             &sync.Mutex{},
26		interrupted:      false,
27		stop:             make(chan interface{}),
28	}
29	handler.registerForInterrupts()
30	return handler
31}
32
33func (handler *FakeInterruptHandler) Stop() {
34	close(handler.stop)
35}
36
37func (handler *FakeInterruptHandler) registerForInterrupts() {
38	go func() {
39		for {
40			select {
41			case <-handler.triggerInterrupt:
42			case <-handler.stop:
43				return
44			}
45			handler.lock.Lock()
46			handler.interrupted = true
47			handler.emittedInterruptPlaceholderMessage = handler.interruptPlaceholderMessage
48			close(handler.c)
49			handler.c = make(chan interface{})
50			handler.lock.Unlock()
51		}
52	}()
53}
54
55func (handler *FakeInterruptHandler) Interrupt(cause interrupt_handler.InterruptCause) {
56	handler.lock.Lock()
57	handler.cause = cause
58	handler.lock.Unlock()
59
60	handler.triggerInterrupt <- true
61}
62
63func (handler *FakeInterruptHandler) Status() interrupt_handler.InterruptStatus {
64	handler.lock.Lock()
65	defer handler.lock.Unlock()
66
67	return interrupt_handler.InterruptStatus{
68		Interrupted: handler.interrupted,
69		Channel:     handler.c,
70		Cause:       handler.cause,
71	}
72}
73
74func (handler *FakeInterruptHandler) SetInterruptPlaceholderMessage(message string) {
75	handler.lock.Lock()
76	defer handler.lock.Unlock()
77
78	handler.interruptPlaceholderMessage = message
79}
80
81func (handler *FakeInterruptHandler) ClearInterruptPlaceholderMessage() {
82	handler.lock.Lock()
83	defer handler.lock.Unlock()
84
85	handler.interruptPlaceholderMessage = ""
86}
87
88func (handler *FakeInterruptHandler) EmittedInterruptPlaceholderMessage() string {
89	handler.lock.Lock()
90	defer handler.lock.Unlock()
91	return handler.emittedInterruptPlaceholderMessage
92}
93
94func (handler *FakeInterruptHandler) InterruptMessageWithStackTraces() string {
95	handler.lock.Lock()
96	defer handler.lock.Unlock()
97
98	return handler.cause.String() + "\nstack trace"
99}
100
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)