<commit_before>//
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package testutil_test

import (
	"fmt"
	"os"
	"testing"
	"time"

	"github.com/01org/ciao/payloads"
	"github.com/01org/ciao/ssntp"
	"github.com/01org/ciao/ssntp/uuid"
	. "github.com/01org/ciao/testutil"
)

var server SsntpTestServer
var controller *SsntpTestController
var agent *SsntpTestClient
var netAgent *SsntpTestClient

func TestSendAgentStatus(t *testing.T) {
	serverCh := server.AddStatusChan(ssntp.READY)

	go agent.SendStatus(16384, 16384)

	_, err := server.GetStatusChanResult(serverCh, ssntp.READY)
	if err != nil {
		t.Fatal(err)
	}
}

func TestSendNetAgentStatus(t *testing.T) {
	serverCh := server.AddStatusChan(ssntp.READY)

	go netAgent.SendStatus(16384, 16384)

	_, err := server.GetStatusChanResult(serverCh, ssntp.READY)
	if err != nil {
		t.Fatal(err)
	}
}

func TestStart(t *testing.T) {
	serverCh := server.AddCmdChan(ssntp.START)
	agentCh := agent.AddCmdChan(ssntp.START)

	go controller.Ssntp.SendCommand(ssntp.START, []byte(StartYaml))

	_, err := agent.GetCmdChanResult(agentCh, ssntp.START)
	if err != nil {
		t.Fatal(err)
	}
	_, err = server.GetCmdChanResult(serverCh, ssntp.START)
	if err != nil {
		t.Fatal(err)
	}
}
<commit_msg>testutil: TestStart wait on server response before agent<commit_after>//
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package testutil_test

import (
	"fmt"
	"os"
	"testing"
	"time"

	"github.com/01org/ciao/payloads"
	"github.com/01org/ciao/ssntp"
	"github.com/01org/ciao/ssntp/uuid"
	. "github.com/01org/ciao/testutil"
)

var server SsntpTestServer
var controller *SsntpTestController
var agent *SsntpTestClient
var netAgent *SsntpTestClient

func TestSendAgentStatus(t *testing.T) {
	serverCh := server.AddStatusChan(ssntp.READY)

	go agent.SendStatus(16384, 16384)

	_, err := server.GetStatusChanResult(serverCh, ssntp.READY)
	if err != nil {
		t.Fatal(err)
	}
}

func TestSendNetAgentStatus(t *testing.T) {
	serverCh := server.AddStatusChan(ssntp.READY)

	go netAgent.SendStatus(16384, 16384)

	_, err := server.GetStatusChanResult(serverCh, ssntp.READY)
	if err != nil {
		t.Fatal(err)
	}
}

func TestStart(t *testing.T) {
	serverCh := server.AddCmdChan(ssntp.START)
	agentCh := agent.AddCmdChan(ssntp.START)

	go controller.Ssntp.SendCommand(ssntp.START, []byte(StartYaml))

	_, err := server.GetCmdChanResult(serverCh, ssntp.START)
	if err != nil {
		t.Fatal(err)
	}
	_, err = agent.GetCmdChanResult(agentCh, ssntp.START)
	if err != nil {
		t.Fatal(err)
	}
}

{'fraction_non_alphanumeric': 0.12059883559744941, 'fraction_numerical': 0.0199611865816468, 'mean_word_length': 4.110481586402266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7125715', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1266, 'n_words': 329}