Exemple #1
0
func TestMutex(t *testing.T) {

	server, err := tempredis.Start(tempredis.Config{})
	if err != nil {
		panic(err)
	}

	config := Redis{
		Protocol:       "unix",
		Address:        server.Socket(),
		MaxIdle:        1,
		MaxConnections: 5,
	}

	config.NewRedisCache()

	err = Cache.Lock("test:mutex")

	assert.NoError(t, err, "An error was not expected")

	assert.True(t, Cache.Unlock("test:mutex"), "Mutex should be unlocked")

	err = Cache.Mutex.Lock("test:mutex")

	assert.NoError(t, err, "An error was not expected")

	err = Cache.Lock("test:mutex")

	assert.NoError(t, err, "An error was not expected")

	assert.True(t, Cache.Unlock("test:mutex"), "Mutex should be unlocked")

	server.Term()

}
Exemple #2
0
func TestNewRedisCache(t *testing.T) {

	server, err := tempredis.Start(tempredis.Config{})
	if err != nil {
		panic(err)
	}

	config := Redis{
		Protocol:       "unix",
		Address:        server.Socket(),
		MaxIdle:        1,
		MaxConnections: 5,
	}

	config.NewRedisCache()

	conn := Cache.Pool.Get()

	_, err = conn.Do("PING")

	assert.NoError(t, err, "An error was not expected")

	conn.Close()

	server.Term()

}
Exemple #3
0
func TestKeysDeleteLock(t *testing.T) {

	server, err := tempredis.Start(tempredis.Config{})
	if err != nil {
		panic(err)
	}

	config := Redis{
		Protocol:       "unix",
		Address:        server.Socket(),
		MaxIdle:        1,
		MaxConnections: 5,
	}

	config.NewRedisCache()

	key := NewKey("index")

	key = key.SetKey("1", "1")

	err = key.Delete()

	assert.NoError(t, err, "An error was not expected")

	server.Term()
}
Exemple #4
0
func TestMain(m *testing.M) {
	var err error
	server, err = tempredis.Start(nil)
	if err != nil {
		panic(err)
	}
	result := m.Run()
	server.Term()
	os.Exit(result)
}
Exemple #5
0
func TestMain(m *testing.M) {
	for i := 0; i < 8; i++ {
		server, err := tempredis.Start(tempredis.Config{})
		if err != nil {
			panic(err)
		}
		servers = append(servers, server)
	}
	result := m.Run()
	for _, server := range servers {
		server.Term()
	}
	os.Exit(result)
}
func setupDB(t *testing.T) *tempredis.Server {
	server, err := tempredis.Start(
		tempredis.Config{
			"port":      TESTING_PORT,
			"databases": "1",
		},
	)

	if err != nil {
		t.Skip("Failed to connect to redis server, so skipping")
	}

	Db, err = redis.Dial(NETWORK, ":"+TESTING_PORT)

	return server
}
func TestMain(m *testing.M) {
	servers = make([]*tempredis.Server, len(addrs))
	for i, addr := range addrs {
		parts := strings.Split(addr.String(), ":")
		port := parts[1]
		server, err := tempredis.Start(tempredis.Config{"port": port})
		if err != nil {
			panic(err)
		}
		defer server.Term()
		servers[i] = server
	}
	result := m.Run()
	for _, server := range servers {
		server.Term()
	}
	os.Exit(result)
}