Skip to content

Conversation

@samliok
Copy link
Collaborator

@samliok samliok commented Jan 20, 2026

This PR refactors the testutil package to better decouple testing helpers and make it easier to compose custom networks, nodes, block builders, and related components.

The refactor introduces a set of building blocks, such as BasicNode and BasicNetwork that encapsulate shared responsibilities like epoch message handling, lifecycle management (start/stop), and essential helper functionality. These primitives can then be composed to build more specialized testing environments, such as LongRunningNetwork or ControlledInMemoryNetwork.

Specialized networks and nodes are responsible for their own additional behavior (e.g., custom block builders, node crash logic, or test-specific helpers), rather than inheriting unused functionality. This avoids the need for a single, monolithic network or node type that accumulates features required only by a subset of tests, keeping the test infrastructure more modular and extensible.

@samliok samliok marked this pull request as ready for review January 20, 2026 22:18
close(t.ingress)
t.running.Wait()
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just like the new code:

func (b *BasicNode) RecordMessageTypeSent(msg *simplex.Message) {
	switch {
	case msg.BlockMessage != nil:
		b.messageTypesSent["BlockMessage"]++
	case msg.VerifiedBlockMessage != nil:
		b.messageTypesSent["VerifiedBlockMessage"]++
	case msg.ReplicationRequest != nil:
		b.messageTypesSent["ReplicationRequest"]++
	case msg.ReplicationResponse != nil:
		b.messageTypesSent["ReplicationResponse"]++
	case msg.Notarization != nil:
		b.messageTypesSent["VerifiedReplicationRequest"]++
	case msg.VerifiedReplicationResponse != nil:
		b.messageTypesSent["VerifiedReplicationResponse"]++
	case msg.Finalization != nil:
		b.messageTypesSent["NotarizationMessage"]++
	case msg.FinalizeVote != nil:
		b.messageTypesSent["FinalizationMessage"]++
	case msg.VoteMessage != nil:
		b.messageTypesSent["VoteMessage"]++
	case msg.EmptyVoteMessage != nil:
		b.messageTypesSent["EmptyVoteMessage"]++
	case msg.EmptyNotarization != nil:
		b.messageTypesSent["EmptyNotarization"]++
	case msg.BlockDigestRequest != nil:
		b.messageTypesSent["BlockDigestRequest"]++
	default:
		panic("unknown message type")
	}
}

Was this file moved and then changed? or was the code just copied?

Is there a way to reduce the diff by git mv and then applying the code changes?

@@ -0,0 +1,74 @@
package long_running
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license header

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added all

Copy link
Collaborator

@yacovm yacovm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be merged after adding license header

@samliok samliok merged commit 1dcef1a into main Feb 3, 2026
2 of 7 checks passed
@samliok samliok deleted the refactor-testutil branch February 3, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants