<commit_before>package renter

import (
	"testing"
	"time"
)

// Stream uses the streaming endpoint to download a file.
func TestAddChunkToCache(t *testing.T) {
	var udc *unfinishedDownloadChunk

	data := []byte{1, 2, 3, 4}
	// Fill Cache
	for i := 0; i < downloadCacheSize; i++ {
		udc.addChunkToCache(data)
		time.Sleep(1 * time.Millisecond)
	}

	// Get oldest key
	var oldestKey string
	oldestTime := time.Now()

	for id, chunk := range udc.chunkCache {
		if chunk.lastAccess.Before(oldestTime) {
			oldestTime = chunk.lastAccess
			oldestKey = id
		}
	}

	udc.addChunkToCache(data)

	// check if the oldestKey was removed
	if _, ok := udc.chunkCache[oldestKey]; ok {
		t.Errorf("Expected ok to be false instead it was %v", ok)
	}

}<commit_msg>TestAddChunkToCache is now passing<commit_after>package renter

import (
	"testing"
	"time"
)

// TestAddChunkToCache tests that the oldest chunk is removed
func TestAddChunkToCache(t *testing.T) {
	var udc unfinishedDownloadChunk
	udc.download = &download{
		staticDestinationType: "httpseekstream",
	}

	data := []byte{1, 2, 3, 4}

	// Fill Cache
	for i := 0; i < downloadCacheSize; i++ {
		udc.addChunkToCache(data)
		time.Sleep(1 * time.Millisecond)
	}

	// Get oldest key
	var oldestKey string
	oldestTime := time.Now()

	for id, chunk := range udc.chunkCache {
		if chunk.lastAccess.Before(oldestTime) {
			oldestTime = chunk.lastAccess
			oldestKey = id
		}
	}

	// Add additional chunk to force deletion of a chunk
	udc.addChunkToCache(data)

	// check if the chunk with the oldestKey was removed
	if _, ok := udc.chunkCache[oldestKey]; ok {
		t.Errorf("Expected ok to be false instead it was %v", ok)
	}

}
{'fraction_non_alphanumeric': 0.11365003006614552, 'fraction_numerical': 0.0072158749248346366, 'mean_word_length': 3.7005649717514126, 'pattern_counts': {'":': 0, '<': 5, '<?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': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4609034', 'n_tokens_mistral': 624, 'n_tokens_neox': 582, 'n_words': 170}