Exemplo n.º 1
0
func TestUpdateUser(t *testing.T) {
	phone := "18801234567"
	secret := "8428d916f8cca9ba5971bf58b34d38da20bc3dff"
	phone2 := "18801234568"

	// insert two
	user, err := models.CreateUserByPhone(&phone, secret)
	assert.Zero(t, err)
	user2, err := models.CreateUserByPhone(&phone2, secret)
	assert.Zero(t, err)

	weixin := "wx:piasy_umumu"
	user.WeiXin = &weixin
	user.Nickname = "Piasy"
	user.Gender = 1
	err = models.UpdateUser(user)
	assert.Zero(t, err)

	got, err := models.GetUserByToken(user.Token)
	assert.Zero(t, err)
	assertUserEquals(t, user, got)

	user.Phone = &phone2
	err = models.UpdateUser(user)
	assert.Equal(t, utils.ERROR_CODE_SYSTEM_ERROR, err)

	deleteUser(t, user.Id)
	deleteUser(t, user2.Id)
}
Exemplo n.º 2
0
func TestRouteExpiry(t *testing.T) {
	allConnections := [][]int{
		[]int{0, 1, 0},
		[]int{1, 0, 1},
		[]int{0, 1, 0},
	}

	nodes, toClose, transports := SetupNodes((uint)(3), allConnections, t)
	defer close(toClose)
	defer func() {
		for _, node := range nodes {
			node.Close()
		}
	}()

	addedRouteID := domain.RouteID{}
	addedRouteID[0] = 55
	addedRouteID[1] = 4

	assert.Nil(t, nodes[0].AddRoute(addedRouteID, nodes[1].GetConfig().PubKey))
	{
		lastConfirmed, err := nodes[0].GetRouteLastConfirmed(addedRouteID)
		assert.Nil(t, err)
		assert.Zero(t, lastConfirmed.Unix())
	}
	assert.Nil(t, nodes[0].ExtendRoute(addedRouteID, nodes[2].GetConfig().PubKey, time.Second))
	assert.NotZero(t, nodes[1].DebugCountRoutes())

	var afterExtendConfirmedTime time.Time
	{
		lastConfirmed, err := nodes[0].GetRouteLastConfirmed(addedRouteID)
		assert.Nil(t, err)
		afterExtendConfirmedTime = lastConfirmed
	}

	time.Sleep(5 * time.Second)
	assert.NotZero(t, nodes[1].DebugCountRoutes())
	var afterWaitConfirmedTime time.Time
	{
		lastConfirmed, err := nodes[0].GetRouteLastConfirmed(addedRouteID)
		assert.Nil(t, err)
		afterWaitConfirmedTime = lastConfirmed
	}

	// Don't allow refreshes to get thru
	transports[0].SetIgnoreSendStatus(true)
	time.Sleep(5 * time.Second)
	var afterIgnoreConfirmedTime time.Time
	{
		lastConfirmed, err := nodes[0].GetRouteLastConfirmed(addedRouteID)
		assert.Nil(t, err)
		afterIgnoreConfirmedTime = lastConfirmed
	}

	assert.Zero(t, nodes[1].DebugCountRoutes())
	assert.NotZero(t, afterExtendConfirmedTime)
	assert.NotZero(t, afterWaitConfirmedTime)
	assert.NotEqual(t, afterExtendConfirmedTime, afterWaitConfirmedTime)
	assert.Equal(t, afterWaitConfirmedTime, afterIgnoreConfirmedTime)
}
Exemplo n.º 3
0
func TestFloat64(t *testing.T) {
	assert := assert.New(t)

	UnsetKey("envconf_test1")
	UnsetKey("envconf_test2")

	v, ok := GetFloat64("envconf_test1")
	assert.False(ok)
	assert.Zero(v)
	assert.Panics(func() { MustGetFloat64("envconf_test1") })

	SetString("envconf_test1", "blahBlah")
	v, ok = GetFloat64("envconf_test1")
	assert.False(ok)
	assert.Zero(v)
	assert.Panics(func() { MustGetFloat64("envconf_test1") })

	SetString("envconf_test1", "83.3")
	v, ok = GetFloat64("envconf_test1")
	assert.True(ok)
	assert.True(floatEquals(83.3, v))
	assert.True(floatEquals(83.3, MustGetFloat64("envconf_test1")))

	SetDefaultFloat64("envconf_test1", -434.43202)
	v, ok = GetFloat64("envconf_test1")
	assert.True(ok)
	assert.True(floatEquals(83.3, v))
	assert.True(floatEquals(83.3, MustGetFloat64("envconf_test1")))

	SetDefaultFloat64("envconf_test2", -0.3424562)
	v, ok = GetFloat64("envconf_test2")
	assert.True(ok)
	assert.True(floatEquals(-0.3424562, v))
	assert.True(floatEquals(-0.3424562, MustGetFloat64("envconf_test2")))
}
Exemplo n.º 4
0
func TestInt(t *testing.T) {
	assert := assert.New(t)

	UnsetKey("envconf_test1")
	UnsetKey("envconf_test2")

	v, ok := GetInt("envconf_test1")
	assert.False(ok)
	assert.Zero(v)
	assert.Panics(func() { MustGetInt("envconf_test1") })

	SetString("envconf_test1", "blahBlah")
	v, ok = GetInt("envconf_test1")
	assert.False(ok)
	assert.Zero(v)
	assert.Panics(func() { MustGetInt("envconf_test1") })

	SetString("envconf_test1", "42")
	v, ok = GetInt("envconf_test1")
	assert.True(ok)
	assert.Equal(42, v)
	assert.Equal(42, MustGetInt("envconf_test1"))

	SetDefaultInt("envconf_test1", -5)
	v, ok = GetInt("envconf_test1")
	assert.True(ok)
	assert.Equal(42, v)
	assert.Equal(42, MustGetInt("envconf_test1"))

	SetDefaultInt("envconf_test2", -33)
	v, ok = GetInt("envconf_test2")
	assert.True(ok)
	assert.Equal(-33, v)
	assert.Equal(-33, MustGetInt("envconf_test2"))
}
Exemplo n.º 5
0
func TestDeleteRoute(t *testing.T) {
	allConnections := [][]int{
		[]int{0, 1, 0},
		[]int{1, 0, 1},
		[]int{0, 1, 0},
	}

	nodes, toClose, _ := SetupNodes((uint)(3), allConnections, t)
	defer close(toClose)
	defer func() {
		for _, node := range nodes {
			node.Close()
		}
	}()
	addedRouteID := domain.RouteID{}
	addedRouteID[0] = 55
	addedRouteID[1] = 4
	assert.Nil(t, nodes[0].AddRoute(addedRouteID, nodes[1].GetConfig().PubKey))
	assert.Nil(t, nodes[0].ExtendRoute(addedRouteID, nodes[2].GetConfig().PubKey, time.Second))
	time.Sleep(5 * time.Second)
	assert.NotZero(t, nodes[0].DebugCountRoutes())
	assert.NotZero(t, nodes[1].DebugCountRoutes())
	assert.Nil(t, nodes[0].DeleteRoute(addedRouteID))
	time.Sleep(1 * time.Second)
	assert.Zero(t, nodes[0].DebugCountRoutes())
	assert.Zero(t, nodes[1].DebugCountRoutes())
}
Exemplo n.º 6
0
func TestDuration(t *testing.T) {
	assert := assert.New(t)

	UnsetKey("envconf_test1")
	UnsetKey("envconf_test2")

	v, ok := GetDuration("envconf_test1")
	assert.False(ok)
	assert.Zero(v)
	assert.Panics(func() { MustGetDuration("envconf_test1") })

	SetString("envconf_test1", "blahBlah")
	v, ok = GetDuration("envconf_test1")
	assert.False(ok)
	assert.Zero(v)
	assert.Panics(func() { MustGetDuration("envconf_test1") })

	SetString("envconf_test1", "15s")
	v, ok = GetDuration("envconf_test1")
	assert.True(ok)
	assert.Equal(15*time.Second, v)
	assert.Equal(15*time.Second, MustGetDuration("envconf_test1"))

	SetDefaultDuration("envconf_test1", 12*time.Millisecond)
	v, ok = GetDuration("envconf_test1")
	assert.True(ok)
	assert.Equal(15*time.Second, v)
	assert.Equal(15*time.Second, MustGetDuration("envconf_test1"))

	SetDefaultDuration("envconf_test2", 33*time.Millisecond)
	v, ok = GetDuration("envconf_test2")
	assert.True(ok)
	assert.Equal(33*time.Millisecond, v)
	assert.Equal(33*time.Millisecond, MustGetDuration("envconf_test2"))
}
Exemplo n.º 7
0
func TestGettingBatches(t *testing.T) {
	b := NewBuffer(20)

	// Verify that the buffer returned is smaller than requested when there are
	// not as many items as requested.
	b.Add(metricList...)
	batch := b.Batch(10)
	assert.Len(t, batch, 5)

	// Verify that the buffer is now empty
	assert.True(t, b.IsEmpty())
	assert.Zero(t, b.Len())
	assert.Zero(t, b.Drops())
	assert.Equal(t, b.Total(), 5)

	// Verify that the buffer returned is not more than the size requested
	b.Add(metricList...)
	batch = b.Batch(3)
	assert.Len(t, batch, 3)

	// Verify that buffer is not empty
	assert.False(t, b.IsEmpty())
	assert.Equal(t, b.Len(), 2)
	assert.Equal(t, b.Drops(), 0)
	assert.Equal(t, b.Total(), 10)
}
Exemplo n.º 8
0
func TestPipeChaining(t *testing.T) {
	tmpdir := setupTestDir(t)
	defer os.RemoveAll(tmpdir)

	h, err := GetExternalHandlerFromMimeType("text/plain")
	assert.Nil(t, err)

	mh, err := GetExternalHandlerFromMimeType("application/x-bzip2")
	assert.Nil(t, err)

	fh, err := ioutil.TempFile(tmpdir, "outfile")
	assert.Nil(t, err)

	start_r, err := h.Decompress(path.Join(tmpdir, "pipechaining"))
	assert.Nil(t, err)

	mr, err := mh.CompressStream(start_r)
	assert.Nil(t, err)

	_, err = io.Copy(fh, mr)
	assert.Nil(t, err)

	//fh.Close()
	//start_r.Close()
	//mr.Close()

	// Check job results
	assert.Zero(t, start_r.Result())
	assert.Zero(t, mr.Result())
}
func TestFormWithEmptyContent(t *testing.T) {
	identifier := vari.NewVarID("TestForm")
	exampleForm := NewForm(identifier, NewEmptyStmtList())

	assert.Equal(t, exampleForm.Identifier(), identifier)
	assert.Zero(t, len(exampleForm.Content().Questions()))
	assert.Zero(t, len(exampleForm.Content().Conditionals()))
}
Exemplo n.º 10
0
func TestSet(t *testing.T) {
	assert.Zero(t, getValue(0))
	Set(0, 1)
	assert.Zero(t, getValue(0))

	const attr = 23456
	for i := 0; i < 10; i++ {
		Set(attr, uint64(i))
		assert.Equal(t, uint64(i), getValue(attr))
	}
}
Exemplo n.º 11
0
func TestAdd(t *testing.T) {
	assert.Zero(t, getValue(0))
	Add(0, 1)
	assert.Zero(t, getValue(0))

	const attr = 123456
	val := getValue(attr)
	for i := 0; i < 10; i++ {
		Add(attr, uint64(i))
		val += uint64(i)
		assert.Equal(t, val, getValue(attr))
	}
}
Exemplo n.º 12
0
func TestBuildWithoutParams(t *testing.T) {
	item := new(Item)

	item.Build(Values)

	assert.True(t, item.Date.IsZero())

	assert.Zero(t, item.CategoryID)

	assert.Zero(t, item.Sum)

	assert.Empty(t, item.Description)
}
Exemplo n.º 13
0
func TestString_ZeroAllocs(t *testing.T) {
	v := "jumped over the lazy dog"
	b := make([]byte, len(v)+1)
	assert.Zero(t, testing.AllocsPerRun(1, func() { PutString(b, v) }))
	assert.Zero(t, testing.AllocsPerRun(1, func() { String(b) }))

	//Note that while the String function requires zero allocations,
	//the decoded string can still escape...
	var x string
	assert.Equal(t, 1.0, testing.AllocsPerRun(1, func() {
		s := String(b)
		x = s
	}))
	assert.Equal(t, v, x)
}
Exemplo n.º 14
0
func TestExpiry(t *testing.T) {
	_, testKeyB, _, _,
		transportA, transportB,
		_, _ := SetupTwoPeers(t)

	testContents := []byte{4, 3, 22, 6, 88, 99}
	assert.Nil(t, transportA.SendMessage(testKeyB, testContents, nil))

	time.Sleep(time.Second)
	assert.NotZero(t, transportA.debug_countMapItems())
	assert.NotZero(t, transportB.debug_countMapItems())
	time.Sleep(7 * time.Second)
	assert.Zero(t, transportA.debug_countMapItems())
	assert.Zero(t, transportB.debug_countMapItems())
}
Exemplo n.º 15
0
func TestFireZerosPotential(t *testing.T) {
	silenceLog()
	na := NewNeuron("A")
	na.potential = 10
	na.Fire()
	assert.Zero(t, na.potential)
}
Exemplo n.º 16
0
func TestLobbyAdd(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()
	defer lobby.Close(false)
	lobby.Save()

	var players []*Player

	for i := 0; i < 12; i++ {
		player := testhelpers.CreatePlayer()
		players = append(players, player)
	}

	// add player
	err := lobby.AddPlayer(players[0], 0, "")
	assert.Nil(t, err)

	slot, err2 := lobby.GetPlayerSlot(players[0])
	assert.Zero(t, slot)
	assert.Nil(t, err2)

	id, err3 := lobby.GetPlayerIDBySlot(0)
	assert.Equal(t, id, players[0].ID)
	assert.Nil(t, err3)

	// try to switch slots
	err = lobby.AddPlayer(players[0], 1, "")
	assert.Nil(t, err)

	slot, err2 = lobby.GetPlayerSlot(players[0])
	assert.Equal(t, slot, 1)
	assert.Nil(t, err2)

	// this should be empty now
	id, err3 = lobby.GetPlayerIDBySlot(0)
	assert.NotNil(t, err3)

	// try to add a second player to the same slot
	err = lobby.AddPlayer(players[1], 1, "")
	assert.NotNil(t, err)

	// try to add a player to a wrong slot slot
	err = lobby.AddPlayer(players[2], 55, "")
	assert.NotNil(t, err)

	lobby2 := testhelpers.CreateLobby()
	defer lobby.Close(false)
	lobby2.Save()

	// try to add a player while they're in another lobby
	//player should be substituted
	lobby.State = LobbyStateInProgress
	lobby.Save()
	err = lobby2.AddPlayer(players[0], 1, "")
	assert.Nil(t, err)

	var count int
	db.DB.Table("lobby_slots").Where("lobby_id = ? AND needs_sub = ?", lobby.ID, true).Count(&count)
	assert.Equal(t, count, 1)
}
Exemplo n.º 17
0
func TestDataStoreDeleteConcurrent(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewMemoryStore()
	ds := NewDataStore(cs)
	datasetID := "ds1"

	datasets := ds.Datasets()
	assert.Zero(datasets.Len())

	// |a|
	a := types.NewString("a")
	aCommit := NewCommit().SetValue(a)
	ds, err := ds.Commit(datasetID, aCommit)
	assert.NoError(err)

	// |a| <- |b|
	b := types.NewString("b")
	bCommit := NewCommit().SetValue(b).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(aCommit.Ref())))
	ds2, err := ds.Commit(datasetID, bCommit)
	assert.NoError(err)
	assert.True(ds.Head(datasetID).Value().Equals(a))
	assert.True(ds2.Head(datasetID).Value().Equals(b))

	ds, err = ds.Delete(datasetID)
	assert.NoError(err)
	h, present := ds.MaybeHead(datasetID)
	assert.False(present, "Dataset %s should not be present, but head is %v", datasetID, h.Value())
	h, present = ds2.MaybeHead(datasetID)
	assert.True(present, "Dataset %s should be present", datasetID)

	// Get a fresh datastore, and verify that no datastores are present
	newDs := NewDataStore(cs)
	datasets = newDs.Datasets()
	assert.Equal(uint64(0), datasets.Len())
}
Exemplo n.º 18
0
func TestDataStoreDelete(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewMemoryStore()
	ds := NewDataStore(cs)
	datasetID1, datasetID2 := "ds1", "ds2"

	datasets := ds.Datasets()
	assert.Zero(datasets.Len())

	// |a|
	a := types.NewString("a")
	ds, err := ds.Commit(datasetID1, NewCommit().SetValue(a))
	assert.NoError(err)
	assert.True(ds.Head(datasetID1).Value().Equals(a))

	// ds1; |a|, ds2: |b|
	b := types.NewString("b")
	ds, err = ds.Commit(datasetID2, NewCommit().SetValue(b))
	assert.NoError(err)
	assert.True(ds.Head(datasetID2).Value().Equals(b))

	ds, err = ds.Delete(datasetID1)
	assert.NoError(err)
	assert.True(ds.Head(datasetID2).Value().Equals(b))
	h, present := ds.MaybeHead(datasetID1)
	assert.False(present, "Dataset %s should not be present, but head is %v", datasetID1, h.Value())

	// Get a fresh datastore, and verify that only ds1 is present
	newDs := NewDataStore(cs)
	datasets = newDs.Datasets()
	assert.Equal(uint64(1), datasets.Len())
	_, present = ds.MaybeHead(datasetID2)
	assert.True(present, "Dataset %s should be present", datasetID2)
}
Exemplo n.º 19
0
func TestPlaying(t *testing.T) {
	sut := getSut()
	assert.Zero(t, sut.Data.Status)

	sut.IsPlaying()
	assert.Equal(t, Playing, sut.Data.Status)
}
Exemplo n.º 20
0
func TestOptionsSetPreflightHeaders(t *testing.T) {
	headers := http.Header{}
	opts := &Options{
		AllowOrigins:     "https://example.com, https://foo.com",
		AllowMethods:     "PUT, PATCH",
		AllowHeaders:     "X-Ping, X-Pong",
		AllowCredentials: false,
		ExposeHeaders:    "X-Ping, X-Pong",
		MaxAge:           time.Duration(100) * time.Second,
	}
	opts.init()
	opts.setPreflightHeaders("https://bar.com", "PUT", "", headers)
	assert.Zero(t, len(headers))

	headers = http.Header{}
	opts.setPreflightHeaders("https://foo.com", "PUT", "X-Pong", headers)
	assert.Equal(t, "https://foo.com", headers.Get(headerAllowOrigin))
	assert.Equal(t, "PUT, PATCH", headers.Get(headerAllowMethods))
	assert.Equal(t, "100", headers.Get(headerMaxAge))
	assert.Equal(t, "X-Pong", headers.Get(headerAllowHeaders))

	headers = http.Header{}
	opts = &Options{
		AllowOrigins: "*",
		AllowMethods: "*",
		AllowHeaders: "*",
	}
	opts.init()
	opts.setPreflightHeaders("https://bar.com", "PUT", "X-Pong", headers)
	assert.Equal(t, "*", headers.Get(headerAllowOrigin))
	assert.Equal(t, "PUT", headers.Get(headerAllowMethods))
	assert.Equal(t, "X-Pong", headers.Get(headerAllowHeaders))
}
Exemplo n.º 21
0
func TestIsPlayed(t *testing.T) {
	sut := getSut()
	assert.Zero(t, sut.Data.Status)

	sut.FinishedPlaying()
	assert.Equal(t, IsPlayed, sut.Data.Status)
}
Exemplo n.º 22
0
func TestRemove(t *testing.T) {
	t.Parallel()
	md, dk := NewMock()

	_, err := dk.Run(RunOptions{Name: "name1"})
	assert.Nil(t, err)

	id2, err := dk.Run(RunOptions{Name: "name2"})
	assert.Nil(t, err)

	md.ListError = true
	err = dk.Remove("name1")
	assert.NotNil(t, err)
	md.ListError = false

	md.RemoveError = true
	err = dk.Remove("name1")
	assert.NotNil(t, err)
	md.RemoveError = false

	err = dk.Remove("unknown")
	assert.NotNil(t, err)

	err = dk.Remove("name1")
	assert.Nil(t, err)

	err = dk.RemoveID(id2)
	assert.Nil(t, err)

	containers, err := dk.list(nil, true)
	assert.Nil(t, err)
	assert.Zero(t, len(containers))
}
Exemplo n.º 23
0
func TestNoDoubleReceive(t *testing.T) {
	_, testKeyB, _, stubTransportB,
		transportA, _,
		_, receivedB := SetupTwoPeers(t)

	// Stop ACK from beint sent back, so the message will be retransmitted
	stubTransportB.SetIgnoreSendStatus(true)
	testContents := []byte{4, 3, 22, 6, 88, 99}
	assert.Nil(t, transportA.SendMessage(testKeyB, testContents, nil))

	receivedTimes := 0

	finishedTime := time.Now().Add(5 * time.Second)

	for time.Now().Before(finishedTime) {
		select {
		case received := <-receivedB:
			{
				assert.Zero(t, receivedTimes)
				receivedTimes++
				assert.Equal(t, testContents, received)
			}
		case <-time.After(time.Second):
		}
	}
}
Exemplo n.º 24
0
func TestValidateOptions(t *testing.T) {
	// Happy Path
	options := newCliOptions()

	options.httpHeaders = []string{"Key1:Value1", "Key2:Value2"}

	code, _ := validateOptions(options)

	assert.Zero(t, code, "Return code should be 0")

	// Error Path
	options.httpVerb = "GOT"

	code, message := validateOptions(options)

	assert.Equal(t, code, 1, "Return code should be 1")
	assert.True(t, strings.Contains(message, "Unexpected HTTP Verb"),
		"Error message should contain \"Unexpected HTTP Verb\"")

	options.httpVerb = "GET"
	options.httpHeaders = []string{"Key1 Value1"}

	code, message = validateOptions(options)

	assert.Equal(t, code, 1, "Return code should be 1")
	assert.True(t, strings.Contains(message, "Unexpected HTTP Header"),
		"Error message should contain \"Unexpected HTTP Header\"")

}
Exemplo n.º 25
0
// TestDefaultMeta tests that WorkSpec.Meta gets the correct defaults,
// which in a couple of cases are not zero values.
func TestDefaultMeta(t *testing.T) {
	sts := SimpleTestSetup{
		NamespaceName: "TestDefaultMeta",
		WorkSpecName:  "spec",
	}
	sts.SetUp(t)
	defer sts.TearDown(t)

	meta, err := sts.WorkSpec.Meta(false)
	if assert.NoError(t, err) {
		assert.Equal(t, 0, meta.Priority)
		assert.Equal(t, 20, meta.Weight)
		assert.False(t, meta.Paused)
		assert.False(t, meta.Continuous)
		assert.False(t, meta.CanBeContinuous)
		assert.Zero(t, meta.Interval)
		assert.WithinDuration(t, time.Time{}, meta.NextContinuous, 1*time.Microsecond)
		assert.Equal(t, 0, meta.MaxRunning)
		assert.Equal(t, 0, meta.MaxAttemptsReturned)
		assert.Equal(t, "", meta.NextWorkSpecName)
		assert.Equal(t, 0, meta.AvailableCount)
		assert.Equal(t, 0, meta.PendingCount)
		assert.Equal(t, "", meta.Runtime)
	}
}
Exemplo n.º 26
0
func TestNotDownloaded(t *testing.T) {
	sut := getSut()
	assert.Zero(t, sut.Data.Status)

	sut.CannotDownload()
	assert.Equal(t, NotDownloaded, sut.Data.Status)
}
Exemplo n.º 27
0
func TestStartHandlersEmptyConfig(t *testing.T) {
	logrus.SetLevel(logrus.PanicLevel)
	handlers := createHandlers(config.Config{})
	startHandlers(handlers)

	assert.Zero(t, len(handlers), "should not create any Handler")
}
Exemplo n.º 28
0
func TestParseIfRedir(t *testing.T) {
	errType := "MOVED"
	slot := uint16(123)
	host := "server:6379"
	redir := errors.New(fmt.Sprintf("%s %d %s", errType, slot, host))
	redirErr, isRedir := parseIfRedir(redir)
	assert.IsType(t, redirectionError{}, redirErr)
	assert.True(t, isRedir)

	nonRedir := errors.New("TOFU 123")
	redirErr, isRedir = parseIfRedir(nonRedir)
	assert.IsType(t, redirectionError{}, redirErr)
	assert.Zero(t, redirErr.errType, "empty type returned")
	assert.Zero(t, redirErr.slot, "empty slot returned")
	assert.False(t, isRedir)
}
Exemplo n.º 29
0
// Test that MaxTCPConections is respected when max==1
func TestConcurrentConns1(t *testing.T) {
	listener := TcpListener{
		ServiceAddress:         ":8196",
		AllowedPendingMessages: 10000,
		MaxTCPConnections:      1,
	}
	listener.parser, _ = parsers.NewInfluxParser()

	acc := &testutil.Accumulator{}
	require.NoError(t, listener.Start(acc))
	defer listener.Stop()

	time.Sleep(time.Millisecond * 25)
	_, err := net.Dial("tcp", "127.0.0.1:8196")
	assert.NoError(t, err)

	// Connection over the limit:
	conn, err := net.Dial("tcp", "127.0.0.1:8196")
	assert.NoError(t, err)
	net.Dial("tcp", "127.0.0.1:8196")
	buf := make([]byte, 1500)
	n, err := conn.Read(buf)
	assert.NoError(t, err)
	assert.Equal(t,
		"Telegraf maximum concurrent TCP connections (1) reached, closing.\n"+
			"You may want to increase max_tcp_connections in"+
			" the Telegraf tcp listener configuration.\n",
		string(buf[:n]))

	_, err = conn.Write([]byte(testMsg))
	assert.NoError(t, err)
	time.Sleep(time.Millisecond * 10)
	assert.Zero(t, acc.NFields())
}
Exemplo n.º 30
0
func TestIsDownloading(t *testing.T) {
	sut := getSut()
	assert.Zero(t, sut.Data.Status)

	sut.IsDownloading()
	assert.Equal(t, IsDownloading, sut.Data.Status)
}