<commit_before>package storage

import (
	"testing"
	"time"

	"os"

	"reflect"

	"sort"

	"bytes"
	"encoding/json"

	"github.com/achilleasa/service-adapters/redis"
	"github.com/achilleasa/trace"
)

var (
	redisEndpoint = ":6379"
)

func init() {
	// Allow test runner to override redis host via the REDIS_HOST env var
	opt := os.Getenv("REDIS_HOST")
	if opt != "" {
		redisEndpoint = opt
	}
}

func TestRedisStorage(t *testing.T) {
	redisSrv := redis.New(redisEndpoint, "", 0, time.Second*10)
	storage := NewRedis(redisSrv)
	defer storage.Close()

	// flush db
	conn, err := redisSrv.GetConnection()
	if err != nil {
		t.Fatalf("Error connecting to redis db: %v", err)
	}
	_, err = conn.Do("FLUSHDB")
	if err != nil {
		t.Fatalf("Error flushing redis db: %v", err)
	}

	now := time.Now()
	traceId := "0f3ac0ef-5282-41aa-b7b7-ed45c4100186"

	// Shuffled records to simulate appends by different processes
	dataSet := trace.Trace{
		trace.Record{Type: trace.Response, From: "com.service3", To: "com.service2", Timestamp: now.Add(time.Second * 3), TraceId: traceId, CorrelationId: "c-2222"},
		trace.Record{Type: trace.Request, From: "com.service2", To: "com.service3", Timestamp: now.Add(time.Second * 2), TraceId: traceId, CorrelationId: "c-2222"},
		trace.Record{Type: trace.Response, From: "com.service2", To: "com.service1", Timestamp: now.Add(time.Second * 4), TraceId: traceId, CorrelationId: "c-1111"},
		trace.Record{Type: trace.Request, From: "com.service1", To: "com.service2", Timestamp: now.Add(time.Second * 1), TraceId: traceId, CorrelationId: "c-1111"},
	}

	// Generate the final sorted set that we will use for comparisons
	sortedDataSet := make(trace.Trace, len(dataSet))
	copy(sortedDataSet, dataSet)
	sort.Sort(sortedDataSet)
<commit_msg>Fixed broken test<commit_after>package storage

import (
	"testing"
	"time"

	"os"

	"reflect"

	"sort"

	"bytes"
	"encoding/json"

	"github.com/achilleasa/service-adapters"
	"github.com/achilleasa/service-adapters/service/redis"
	"github.com/achilleasa/trace"
)

var (
	redisEndpoint = ":6379"
)

func init() {
	// Allow test runner to override redis host via the REDIS_HOST env var
	opt := os.Getenv("REDIS_HOST")
	if opt != "" {
		redisEndpoint = opt
	}
}

func TestRedisStorage(t *testing.T) {
	redisSrv, err := redis.New(adapters.Config(map[string]string{"endpoint": redisEndpoint}))
	if err != nil {
		t.Fatalf("Error creating redis service: %v", err)
	}
	storage := NewRedis(redisSrv)
	defer storage.Close()

	// flush db
	conn, err := redisSrv.GetConnection()
	if err != nil {
		t.Fatalf("Error connecting to redis db: %v", err)
	}
	_, err = conn.Do("FLUSHDB")
	if err != nil {
		t.Fatalf("Error flushing redis db: %v", err)
	}

	now := time.Now()
	traceId := "0f3ac0ef-5282-41aa-b7b7-ed45c4100186"

	// Shuffled records to simulate appends by different processes
	dataSet := trace.Trace{
		trace.Record{Type: trace.Response, From: "com.service3", To: "com.service2", Timestamp: now.Add(time.Second * 3), TraceId: traceId, CorrelationId: "c-2222"},
		trace.Record{Type: trace.Request, From: "com.service2", To: "com.service3", Timestamp: now.Add(time.Second * 2), TraceId: traceId, CorrelationId: "c-2222"},
		trace.Record{Type: trace.Response, From: "com.service2", To: "com.service1", Timestamp: now.Add(time.Second * 4), TraceId: traceId, CorrelationId: "c-1111"},
		trace.Record{Type: trace.Request, From: "com.service1", To: "com.service2", Timestamp: now.Add(time.Second * 1), TraceId: traceId, CorrelationId: "c-1111"},
	}

	// Generate the final sorted set that we will use for comparisons
	sortedDataSet := make(trace.Trace, len(dataSet))
	copy(sortedDataSet, dataSet)
	sort.Sort(sortedDataSet)

{'fraction_non_alphanumeric': 0.15730643402399128, 'fraction_numerical': 0.02917121046892039, 'mean_word_length': 4.575987841945289, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, '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': '641301', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1352, 'n_words': 322}