Fix CI failures in peer ping implementation
Fixed multiple issues causing CI failures: - Fixed C++ build on Linux by excluding macOS-specific source files in miner/core/tests/CMakeLists.txt. - Fixed Go test panic in pkg/mining/manager_test.go by properly checking for nil return from StartMiner. - Fixed runtime panic in pkg/mining/service.go where generateRequestID was attempting to base64 decode a timestamp string; replaced with crypto/rand. - Verified removal of unused fmt import in pkg/ueps/packet.go.
This commit is contained in:
parent
c0d0a24fb9
commit
de8e2c5d94
4 changed files with 20 additions and 5 deletions
|
|
@ -18,8 +18,13 @@ list(FILTER MINER_SOURCES EXCLUDE REGEX ".*_riscv.*")
|
|||
if (WIN32)
|
||||
list(FILTER MINER_SOURCES EXCLUDE REGEX ".*_unix\\.cpp$")
|
||||
list(FILTER MINER_SOURCES EXCLUDE REGEX ".*_linux\\.cpp$")
|
||||
list(FILTER MINER_SOURCES EXCLUDE REGEX ".*_mac\\.cpp$")
|
||||
elseif (APPLE)
|
||||
list(FILTER MINER_SOURCES EXCLUDE REGEX ".*_win\\.cpp$")
|
||||
list(FILTER MINER_SOURCES EXCLUDE REGEX ".*_linux\\.cpp$")
|
||||
else()
|
||||
list(FILTER MINER_SOURCES EXCLUDE REGEX ".*_win\\.cpp$")
|
||||
list(FILTER MINER_SOURCES EXCLUDE REGEX ".*_mac\\.cpp$")
|
||||
endif()
|
||||
|
||||
# Create a library with common test utilities and miner components
|
||||
|
|
|
|||
|
|
@ -151,7 +151,14 @@ func TestGetMiner_Good(t *testing.T) {
|
|||
}
|
||||
|
||||
// Case 1: Get an existing miner
|
||||
startedMiner, _ := m.StartMiner(context.Background(), "xmrig", config)
|
||||
startedMiner, err := m.StartMiner(context.Background(), "xmrig", config)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to start miner: %v", err)
|
||||
}
|
||||
if startedMiner == nil {
|
||||
t.Fatal("StartMiner returned nil miner")
|
||||
}
|
||||
|
||||
retrievedMiner, err := m.GetMiner(startedMiner.GetName())
|
||||
if err != nil {
|
||||
t.Fatalf("Expected to get miner, but got error: %v", err)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package mining
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
|
@ -203,9 +204,12 @@ func requestIDMiddleware() gin.HandlerFunc {
|
|||
|
||||
// generateRequestID creates a unique request ID using timestamp and random bytes
|
||||
func generateRequestID() string {
|
||||
b := make([]byte, 8)
|
||||
_, _ = base64.StdEncoding.Decode(b, []byte(fmt.Sprintf("%d", time.Now().UnixNano())))
|
||||
return fmt.Sprintf("%d-%x", time.Now().UnixMilli(), b[:4])
|
||||
b := make([]byte, 4)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
// Fallback if random source fails (unlikely)
|
||||
return fmt.Sprintf("%d", time.Now().UnixNano())
|
||||
}
|
||||
return fmt.Sprintf("%d-%x", time.Now().UnixMilli(), b)
|
||||
}
|
||||
|
||||
// getRequestID extracts the request ID from gin context
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue