<commit_before>// Copyright (c) 2014-2017 <NAME>
// Licensed under the MIT license

package daemon

import (
    "fmt"
    "github.com/etix/mirrorbits/database"
    "github.com/etix/mirrorbits/mirrors"
    . "github.com/etix/mirrorbits/testing"
    "reflect"
    "sort"
    "testing"
    "time"
)

func TestStart(t *testing.T) {
    _, conn := PrepareRedisTest()
    conn.ConnectPubsub()

    c := NewCluster(conn)
    c.Start()
    defer c.Stop()

    if c.running != true {
        t.Fatalf("Expected true, got false")
    }
}

func TestStop(t *testing.T) {
    _, conn := PrepareRedisTest()
    conn.ConnectPubsub()

    c := NewCluster(conn)
    c.Start()
    c.Stop()

    if c.running != false {
        t.Fatalf("Expected false, got true")
    }
}

func TestClusterLoop(t *testing.T) {
    mock, conn := PrepareRedisTest()
    conn.ConnectPubsub()

    c := NewCluster(conn)

    cmd_publish := mock.Command("PUBLISH", string(database.CLUSTER), fmt.Sprintf("%s %s", clusterAnnounce, c.nodeID)).Expect("1")

    c.Start()
    defer c.Stop()

    n := time.Now()

    for {
        if time.Now().Sub(n) > 1500*time.Millisecond {
            t.Fatalf("Announce not made")
        }
        if mock.Stats(cmd_publish) > 0 {
            // Success
            break
        }
    }
}

func TestRefreshNodeList(t *testing.T) {
    _, conn := PrepareRedisTest()
    conn.ConnectPubsub()

    c := NewCluster(conn)

    n := Node{
        ID:           "test-4242",
        LastAnnounce: time.Now().UTC().Unix(),<commit_msg>tests: cool down between retries<commit_after>// Copyright (c) 2014-2017 <NAME>
// Licensed under the MIT license

package daemon

import (
    "fmt"
    "github.com/etix/mirrorbits/database"
    "github.com/etix/mirrorbits/mirrors"
    . "github.com/etix/mirrorbits/testing"
    "reflect"
    "sort"
    "testing"
    "time"
)

func TestStart(t *testing.T) {
    _, conn := PrepareRedisTest()
    conn.ConnectPubsub()

    c := NewCluster(conn)
    c.Start()
    defer c.Stop()

    if c.running != true {
        t.Fatalf("Expected true, got false")
    }
}

func TestStop(t *testing.T) {
    _, conn := PrepareRedisTest()
    conn.ConnectPubsub()

    c := NewCluster(conn)
    c.Start()
    c.Stop()

    if c.running != false {
        t.Fatalf("Expected false, got true")
    }
}

func TestClusterLoop(t *testing.T) {
    mock, conn := PrepareRedisTest()
    conn.ConnectPubsub()

    c := NewCluster(conn)

    cmd_publish := mock.Command("PUBLISH", string(database.CLUSTER), fmt.Sprintf("%s %s", clusterAnnounce, c.nodeID)).Expect("1")

    c.Start()
    defer c.Stop()

    n := time.Now()

    for {
        if time.Since(n) > 1500*time.Millisecond {
            t.Fatalf("Announce not made")
        }
        if mock.Stats(cmd_publish) > 0 {
            // Success
            break
        }
        time.Sleep(50 * time.Millisecond)
    }
}

func TestRefreshNodeList(t *testing.T) {
    _, conn := PrepareRedisTest()
    conn.ConnectPubsub()

    c := NewCluster(conn)

    n := Node{
        ID:           "test-4242",
        LastAnnounce: time.Now().UTC().Unix(),
{'fraction_non_alphanumeric': 0.1498549790525298, 'fraction_numerical': 0.012246213341927168, 'mean_word_length': 2.298618490967056, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '5287295', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1059, 'n_words': 211}