Skip to content

Commit e68f46d

Browse files
committed
fix(tests): Try to stabilize flaky tests
1 parent ee4a3a3 commit e68f46d

File tree

2 files changed

+18
-38
lines changed

2 files changed

+18
-38
lines changed

internal/etw/source_test.go

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ package etw
2020
import (
2121
"context"
2222
"fmt"
23+
"net"
24+
"net/http"
25+
"os"
26+
"os/exec"
27+
"path/filepath"
28+
"runtime"
29+
"strings"
30+
"syscall"
31+
"testing"
32+
"time"
33+
"unsafe"
34+
2335
"github.com/rabbitstack/fibratus/internal/evasion"
2436
"github.com/rabbitstack/fibratus/pkg/config"
2537
"github.com/rabbitstack/fibratus/pkg/event"
@@ -39,17 +51,6 @@ import (
3951
"github.com/stretchr/testify/require"
4052
"golang.org/x/sys/windows"
4153
"golang.org/x/sys/windows/registry"
42-
"net"
43-
"net/http"
44-
"os"
45-
"os/exec"
46-
"path/filepath"
47-
"runtime"
48-
"strings"
49-
"syscall"
50-
"testing"
51-
"time"
52-
"unsafe"
5354
)
5455

5556
// MockListener receives the event and does nothing but indicating the event was processed.
@@ -626,30 +627,8 @@ func TestEventSourceAllEvents(t *testing.T) {
626627
{
627628
"duplicate handle",
628629
func() error {
629-
var si windows.StartupInfo
630-
var pi windows.ProcessInformation
631-
argv, err := windows.UTF16PtrFromString(filepath.Join(os.Getenv("windir"), "notepad.exe"))
632-
if err != nil {
633-
return err
634-
}
635-
err = windows.CreateProcess(
636-
nil,
637-
argv,
638-
nil,
639-
nil,
640-
true,
641-
0,
642-
nil,
643-
nil,
644-
&si,
645-
&pi)
646-
if err != nil {
647-
return err
648-
}
649-
time.Sleep(time.Second)
650-
defer windows.TerminateProcess(pi.Process, 0)
651630
hs := handle.NewSnapshotter(&config.Config{EnumerateHandles: true}, nil)
652-
handles, err := hs.FindHandles(pi.ProcessId)
631+
handles, err := hs.FindHandles(uint32(os.Getppid()))
653632
if err != nil {
654633
return err
655634
}
@@ -660,7 +639,7 @@ func TestEventSourceAllEvents(t *testing.T) {
660639
}
661640
}
662641
assert.False(t, dupHandleID == 0)
663-
dup, err := handle.Duplicate(dupHandleID, pi.ProcessId, windows.KEY_READ)
642+
dup, err := handle.Duplicate(dupHandleID, uint32(os.Getppid()), 0)
664643
if err != nil {
665644
return err
666645
}

pkg/pe/parser_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
package pe
2020

2121
import (
22-
"github.com/stretchr/testify/require"
23-
"golang.org/x/sys/windows"
2422
"os"
2523
"path/filepath"
2624
"testing"
2725
"time"
26+
27+
"github.com/stretchr/testify/require"
28+
"golang.org/x/sys/windows"
2829
)
2930

3031
func TestParseFile(t *testing.T) {
@@ -106,7 +107,7 @@ func TestParseMem(t *testing.T) {
106107
executable string
107108
expectedSections int
108109
}{
109-
{filepath.Join(os.Getenv("windir"), "notepad.exe"), 7},
110+
{filepath.Join(os.Getenv("windir"), "regedit.exe"), 8},
110111
}
111112

112113
for _, tt := range tests {

0 commit comments

Comments
 (0)