<commit_before>package swarm

import (
	"network"
	"testing"
	"time"
)

func TestStateSteady(t *testing.T) {
	mult := network.NewNetworkMultiplexer()
	hosts := []string{"A", "B", "C", "D"}
	swarm := "test"
	var swarms []*Blockchain
	hostsseen := make(map[string]int)
	baseblock := &Block{"", swarm, "", nil, nil}
	for i := 0; i < len(hosts); i++ {
		// Create all the blockchains and let them do nothing.
		swarms = append(swarms, NewBlockchain(hosts[i], swarm, nil))
		if state, ok := swarms[i].state.(*StateSwarmInformed); ok {
			// Prevent race hazards
			state.Die(true)
		}
		hostsseen[hosts[i]] = 1
		swarms[i].AddSource(mult)
	}
	for i := 0; i < len(swarms); i++ {
		// Set all blockchains to StateSteady
		// The initial secret string needs to be unique, use host ID
		swarms[i].state = NewStateSteady(swarms[i], baseblock, hostsseen, hosts[i])
	}
	time.Sleep(time.Second)
	// Die swarm, you don't belong in this world
	for _, v := range swarms {
		switch s := v.state.(type) {
		case *StateSteady:
			s.die <- struct{}{}
		default:
			t.Fatal("State unexpectedly changed")
		}
	}
}<commit_msg>Fix race condition in Steady test.<commit_after>package swarm

import (
	"network"
	"testing"
	"time"
)

func TestStateSteady(t *testing.T) {
	mult := network.NewNetworkMultiplexer()
	hosts := []string{"A", "B", "C", "D"}
	swarm := "test"
	var swarms []*Blockchain
	hostsseen := make(map[string]int)
	baseblock := &Block{"", swarm, "", nil, nil}
	for i := 0; i < len(hosts); i++ {
		// Create all the blockchains and let them do nothing.
		swarms = append(swarms, NewBlockchain(hosts[i], swarm, nil))
		if state, ok := swarms[i].state.(*StateSwarmInformed); ok {
			// Prevent race hazards
			state.Die(true)
		}
		hostsseen[hosts[i]] = 1
		swarms[i].AddSource(mult)
	}
	for i := 0; i < len(swarms); i++ {
		// Set all blockchains to StateSteady
		// The initial secret string needs to be unique, use host ID
		swarms[i].lock.Lock()
		swarms[i].state = NewStateSteady(swarms[i], baseblock, hostsseen, hosts[i])
		swarms[i].lock.Lock()
	}
	time.Sleep(time.Second)
	// Die swarm, you don't belong in this world
	for _, v := range swarms {
		switch s := v.state.(type) {
		case *StateSteady:
			s.die <- struct{}{}
		default:
			t.Fatal("State unexpectedly changed")
		}
	}
}
{'fraction_non_alphanumeric': 0.1657142857142857, 'fraction_numerical': 0.0026373626373626374, 'mean_word_length': 3.791578947368421, 'pattern_counts': {'":': 0, '<': 9, '<?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': '7195300', 'n_tokens_mistral': 917, 'n_tokens_neox': 825, 'n_words': 229}