<commit_before>package gateway

import (
	"testing"
)

func TestLoad(t *testing.T) {
	g := newTestingGateway("TestLoad", t)
	id := g.mu.Lock()
	g.addNode("foo")
	g.save()
	g.mu.Unlock(id)
	g.Close()

	g2, err := New(":0", g.saveDir)
	if err != nil {
		t.Fatal(err)
	}
	if _, ok := g2.nodes["foo"]; !ok {
		t.Fatal("gateway did not load old peer list:", g2.nodes)
	}
}<commit_msg>add persist load peer test<commit_after>package gateway

import (
	"testing"
	"time"

	"github.com/NebulousLabs/Sia/modules"
)

func TestLoad(t *testing.T) {
	g := newTestingGateway("TestLoad", t)
	id := g.mu.Lock()
	g.addNode("foo")
	g.save()
	g.mu.Unlock(id)
	g.Close()

	g2, err := New(":0", g.saveDir)
	if err != nil {
		t.Fatal(err)
	}
	if _, ok := g2.nodes["foo"]; !ok {
		t.Fatal("gateway did not load old peer list:", g2.nodes)
	}
}

func TestLoadPeer(t *testing.T) {
	g1 := newTestingGateway("TestLoadPeer1", t)
	g2 := newTestingGateway("TestLoadPeer2", t)

	err := g1.Connect(g2.Address())
	if err != nil {
		t.Fatal("couldn't connect")
	}
	// g2 is now in g1's node and peer list
	g1.Close()

	// g1 should reconnect to g2 upon load
	g1, err = New(":0", g1.saveDir)
	if err != nil {
		t.Fatal(err)
	}
	time.Sleep(10 * time.Millisecond)
	peers := g1.Peers()
	if len(peers) != 1 || peers[0] != g2.Address() {
		t.Fatalf("gateway did not reconnect to loaded peer: expected %v, got %v", []modules.NetAddress{g2.Address()}, peers)
	}
}
{'fraction_non_alphanumeric': 0.19014084507042253, 'fraction_numerical': 0.020422535211267606, 'mean_word_length': 3.705298013245033, 'pattern_counts': {'":': 3, '<': 3, '<?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': '6251560', 'n_tokens_mistral': 623, 'n_tokens_neox': 600, 'n_words': 141}