Skip to content

Commit e2148c0

Browse files
committed
hivesim,libhive: Simplify client registration
1 parent be4f876 commit e2148c0

File tree

6 files changed

+121
-311
lines changed

6 files changed

+121
-311
lines changed

hivesim/hive.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ func (sim *Simulation) StartSharedClient(testSuite SuiteID, clientType string, o
224224
config: simapi.NodeConfig{
225225
Client: clientType,
226226
Environment: make(map[string]string),
227-
IsShared: true, // Mark this client as shared
228227
},
229228
}
230229
for _, opt := range options {
@@ -285,30 +284,19 @@ func (sim *Simulation) ExecSharedClient(testSuite SuiteID, clientID string, cmd
285284
}
286285

287286
// RegisterNode registers a client with a test. This is normally handled
288-
// automatically by StartClient, but can be used directly to register a reference
289-
// to a shared client.
290-
func (sim *Simulation) RegisterNode(testSuite SuiteID, test TestID, clientID string, nodeInfo *simapi.NodeInfo) error {
287+
// automatically by StartClient, but can be used directly by a test to
288+
// register a reference to a shared client.
289+
func (sim *Simulation) RegisterNode(testSuite SuiteID, test TestID, clientID string) error {
291290
if sim.docs != nil {
292291
return errors.New("RegisterNode is not supported in docs mode")
293292
}
294293

295-
// We'll use the startClient endpoint with a special parameter to register a shared client
296-
var (
297-
url = fmt.Sprintf("%s/testsuite/%d/test/%d/node", sim.url, testSuite, test)
298-
config = simapi.NodeConfig{
299-
Client: nodeInfo.Name,
300-
SharedClientID: clientID,
301-
}
302-
)
303-
304-
// Set up a client setup object to post with files (even though we don't have any files)
305-
setup := &clientSetup{
306-
files: make(map[string]func() (io.ReadCloser, error)),
307-
config: config,
294+
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/testsuite/%d/node/%s/test/%d", sim.url, testSuite, clientID, test), nil)
295+
if err != nil {
296+
return err
308297
}
309-
310-
var resp simapi.StartNodeResponse
311-
return setup.postWithFiles(url, &resp)
298+
_, err = http.DefaultClient.Do(req)
299+
return err
312300
}
313301

314302
// StopClient signals to the host that the node is no longer required.

hivesim/testapi.go

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package hivesim
33
import (
44
"context"
55
"fmt"
6-
"io"
76
"net"
87
"os"
98
"runtime"
@@ -232,9 +231,9 @@ type Client struct {
232231
test *T
233232

234233
// Fields for shared client support
235-
IsShared bool // Whether this client is shared across tests
236-
LogPosition int64 // Current position in the log file (for shared clients)
237-
SuiteID SuiteID // The suite this client belongs to (for shared clients)
234+
IsShared bool // Whether this client is shared across tests
235+
LogPosition int64 // Current position in the log file (for shared clients)
236+
SuiteID SuiteID // The suite this client belongs to (for shared clients)
238237
}
239238

240239
// EnodeURL returns the default peer-to-peer endpoint of the client.
@@ -347,7 +346,7 @@ func (t *T) GetSharedClient(clientID string) *Client {
347346
// Use the position from the client object as a fallback
348347
currentLogPosition = sharedClient.LogPosition
349348
}
350-
349+
351350
// Store the test context in the client so it can be used for this test
352351
// Create a new Client instance that points to the same container
353352
client := &Client{
@@ -373,25 +372,7 @@ func (t *T) GetSharedClient(clientID string) *Client {
373372

374373
t.Logf("Using shared client %s with log position %d", clientID, currentLogPosition)
375374

376-
// Register this shared client with the test using the startClient endpoint with a special parameter
377-
// This makes it appear in the test's ClientInfo so the UI can display the logs correctly
378-
var (
379-
config = simapi.NodeConfig{
380-
Client: sharedClient.Type,
381-
SharedClientID: clientID,
382-
}
383-
)
384-
385-
// Set up a client setup object to post with files (even though we don't have any files)
386-
setup := &clientSetup{
387-
files: make(map[string]func() (io.ReadCloser, error)),
388-
config: config,
389-
}
390-
391-
url := fmt.Sprintf("%s/testsuite/%d/test/%d/node", t.Sim.url, t.SuiteID, t.TestID)
392-
var resp simapi.StartNodeResponse
393-
err = setup.postWithFiles(url, &resp)
394-
if err != nil {
375+
if err := t.Sim.RegisterNode(t.SuiteID, t.TestID, clientID); err != nil {
395376
t.Logf("Warning: Failed to register shared client %s with test: %v", clientID, err)
396377
} else {
397378
t.Logf("Successfully registered shared client %s with test %d", clientID, t.TestID)
@@ -524,9 +505,9 @@ func runTest(host *Simulation, test testSpec, runit func(t *T)) error {
524505

525506
// Register test on simulation server and initialize the T.
526507
t := &T{
527-
Sim: host,
528-
SuiteID: test.suiteID,
529-
suite: test.suite,
508+
Sim: host,
509+
SuiteID: test.suiteID,
510+
suite: test.suite,
530511
clientLogOffsets: make(map[string]*LogOffset), // Initialize log offset tracking
531512
}
532513
testID, err := host.StartTest(test.suiteID, test.request())

0 commit comments

Comments
 (0)