<commit_before>require 'rubygems'
require 'bud'
require 'test/unit'
require 'raft'
require 'pry'

class TestRaft < Test::Unit::TestCase
  class RaftBloom
    include Bud
    include Raft 
  end

  def test_raft
    p1 = RaftBloom.new(:port=>54321)
    p1.run_bg

    p2 = RaftBloom.new(:port=>54322)
    p2.run_bg

    p3 = RaftBloom.new(:port=>54323)
    p3.run_bg

    p4 = RaftBloom.new(:port=>54324)
    p4.run_bg

    p5 = RaftBloom.new(:port=>54325)
    p5.run_bg

    #TEST CASE 1: Make Sure Each Node starts off as a follower
    listOfServers = [p1, p2, p3, p4, p5]
    listOfServers.each do |server|
      server.sync_do do 
        assert_equal(server.server_state.values[0], ["follower"])
      end
    end

    (1..10).each { listOfServers.each {|s| s.sync_do } }

    binding.pry
    1==1

    # acks = p1.sync_callback(:kvput, [[1, :joe, 1, :hellerstein]], :kv_acks)
    # assert_equal([[1]], acks)

    p1.stop
    p2.stop
    p3.stop
    p4.stop
    p5.stop
  end
end
<commit_msg>Add a few happy path tests<commit_after>require 'rubygems'
require 'bud'
require 'test/unit'
require 'raft'
require 'pry'

class TestRaft < Test::Unit::TestCase
  class RaftBloom
    include Bud
    include Raft 
  end

  def test_raft
    p1 = RaftBloom.new(:port=>54321)
    p1.run_bg

    p2 = RaftBloom.new(:port=>54322)
    p2.run_bg

    p3 = RaftBloom.new(:port=>54323)
    p3.run_bg

    p4 = RaftBloom.new(:port=>54324)
    p4.run_bg

    p5 = RaftBloom.new(:port=>54325)
    p5.run_bg

    p6 = RaftBloom.new(:port=>54326)
    p6.run_bg


    #TEST CASE 1: Make Sure Each Node starts off as a follower
    listOfServers = [p1, p2, p3, p4, p5]
    listOfServers.each do |server|
      server.sync_do do 
        assert_equal(server.server_state.values[0], ["follower"])
      end
    end

    # TEST 2: test that a leader is initially elected
    # tick servers and assume normal operation
    (1..10).each { 
      listOfServers.each {|s| s.sync_do } 
    }
    assert listOfServers.map {|s| s.server_state.values[0].first }.any? {|str| str == 'leader'}

    # TEST 3: test that there is exactly one leader
    assert listOfServers.map {|s| s.server_state.values[0].first }.select {|str| str == 'leader'}.count == 1

    # TEST 4: test that when a leader goes offline, a new leader is elected
    # find and stop the current leader:
    leader = listOfServers.select {|s| s.server_state.values[0].first == 'leader'}.first
    leader.stop
    listOfServers.delete(leader) # remove stopped server from listOfServers
    (1..10).each { listOfServers.each {|s| s.sync_do } }
    # now test that there is exactly one leader
    assert listOfServers.map {|s| s.server_state.values[0].first }.select {|str| str == 'leader'}.count == 1

    p1.stop
    p2.stop
    p3.stop
    p4.stop
    p5.stop
    p6.stop
  end
end

{'fraction_non_alphanumeric': 0.12384669978708304, 'fraction_numerical': 0.044712562100780694, 'mean_word_length': 2.799191374663073, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '852165', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1065, 'n_words': 264}