<commit_before>package node

import (
	"testing"
	"time"
)

func LinkRouters(a, b router) {
	c1, c2 := makePairedConnections(a.GetAddress(), b.GetAddress())
	a.AddConnection(c2)
	b.AddConnection(c1)
}

func TestNode(t *testing.T) {
	sk1, _ := NewECDSAKey()
	sk2, _ := NewECDSAKey()
	c := make(chan time.Time)
	n1 := NewNode(sk1, time.Tick(100*time.Millisecond), c)
	n2 := NewNode(sk2, time.Tick(100*time.Millisecond), time.Tick(100*time.Millisecond))
	defer n1.Close()
	defer n2.Close()
	link(n1, n2)

	p2 := testPacket(sk2.PublicKey().Hash())
	n1.SendPacket(p2)
	<-n2.Packets()

	for range time.Tick(25 * time.Millisecond) {
		if amt, _ := n1.router.OutgoingDebt(sk2.PublicKey().Hash()); amt != 0 {
			break
		}
	}

	c <- time.Now()

	for range time.Tick(25 * time.Millisecond) {
		if amt, _ := n1.router.OutgoingDebt(sk2.PublicKey().Hash()); amt == 0 {
			return
		}
	}
}<commit_msg>Correct check the error when sending packets in node_test.go<commit_after>package node

import (
	"testing"
	"time"
)

func LinkRouters(a, b router) {
	c1, c2 := makePairedConnections(a.GetAddress(), b.GetAddress())
	a.AddConnection(c2)
	b.AddConnection(c1)
}

func TestNode(t *testing.T) {
	sk1, _ := NewECDSAKey()
	sk2, _ := NewECDSAKey()
	c := make(chan time.Time)
	n1 := NewNode(sk1, time.Tick(100*time.Millisecond), c)
	n2 := NewNode(sk2, time.Tick(100*time.Millisecond), time.Tick(100*time.Millisecond))
	defer n1.Close()
	defer n2.Close()
	link(n1, n2)

	if !n1.IsReachable(sk2.PublicKey().Hash()) {
		t.Fatalf("n2 is not reachable")
	}

	p2 := testPacket(sk2.PublicKey().Hash())
	err := n1.SendPacket(p2)
	if err != nil {
		t.Fatalf("Error sending packet: %v", err)
	}
	<-n2.Packets()

	for range time.Tick(25 * time.Millisecond) {
		if amt, _ := n1.router.OutgoingDebt(sk2.PublicKey().Hash()); amt != 0 {
			break
		}
	}

	c <- time.Now()

	for range time.Tick(25 * time.Millisecond) {
		if amt, _ := n1.router.OutgoingDebt(sk2.PublicKey().Hash()); amt == 0 {
			return
		}
	}
}
{'fraction_non_alphanumeric': 0.18052738336713997, 'fraction_numerical': 0.04006085192697769, 'mean_word_length': 4.098191214470284, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5671926', 'n_tokens_mistral': 887, 'n_tokens_neox': 827, 'n_words': 153}