<commit_before>package integrate

import (
	"log"
	"os"
	"path/filepath"
	"sync"
	"testing"
	"time"

	"github.com/sourcegraph/jsonrpc2"
	"github.com/stretchr/testify/assert"

	"github.com/itchio/butler/butlerd"
	"github.com/itchio/butler/butlerd/messages"
	itchio "github.com/itchio/go-itchio"
)

func Test_InstallCancel(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping test in short mode")
	}

	rc, h, cancel := connect(t)
	defer cancel()

	authenticate(t, rc)
	setupTmpInstallLocation(t, h, rc)

	_, err := messages.NetworkSetBandwidthThrottle.TestCall(rc, &butlerd.NetworkSetBandwidthThrottleParams{
		Enabled: true,
		Rate:    16384,
	})
	must(t, err)

	defer func() {
		_, err := messages.NetworkSetBandwidthThrottle.TestCall(rc, &butlerd.NetworkSetBandwidthThrottleParams{
			Enabled: false,
		})
		must(t, err)
	}()

	{
		// itch-test-account/big-assets
		game := getGame(t, h, rc, 243485)

		queueRes, err := messages.InstallQueue.TestCall(rc, &butlerd.InstallQueueParams{
			Game:              game,
			InstallLocationID: "tmp",
		})
		must(t, err)

		pidFilePath := filepath.Join(queueRes.StagingFolder, "operate-pid.json")

		var lastProgressValue float64
		printProgress := func(params *butlerd.ProgressNotification) {
			log.Printf("%.2f%% done @ %s / s ETA %s", params.Progress*100, progress.FormatBytes(params.BPS)), time.Duration(params.ETA*float64(time.Second)))
			lastProgressValue = params.Progress
		}

		gracefulCancelOnce := &sync.Once{}

		messages.Progress.Register(h, func(rc *butlerd.RequestContext, params *butlerd.ProgressNotification) {
			printProgress(params)

			if params.Progress > 0.2 {<commit_msg>fix tests<commit_after>package integrate

import (
	"log"
	"os"
	"path/filepath"
	"sync"
	"testing"
	"time"

	"github.com/sourcegraph/jsonrpc2"
	"github.com/stretchr/testify/assert"

	"github.com/itchio/butler/butlerd"
	"github.com/itchio/butler/butlerd/messages"
	itchio "github.com/itchio/go-itchio"
	"github.com/itchio/httpkit/progress"
)

func Test_InstallCancel(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping test in short mode")
	}

	rc, h, cancel := connect(t)
	defer cancel()

	authenticate(t, rc)
	setupTmpInstallLocation(t, h, rc)

	_, err := messages.NetworkSetBandwidthThrottle.TestCall(rc, &butlerd.NetworkSetBandwidthThrottleParams{
		Enabled: true,
		Rate:    16384,
	})
	must(t, err)

	defer func() {
		_, err := messages.NetworkSetBandwidthThrottle.TestCall(rc, &butlerd.NetworkSetBandwidthThrottleParams{
			Enabled: false,
		})
		must(t, err)
	}()

	{
		// itch-test-account/big-assets
		game := getGame(t, h, rc, 243485)

		queueRes, err := messages.InstallQueue.TestCall(rc, &butlerd.InstallQueueParams{
			Game:              game,
			InstallLocationID: "tmp",
		})
		must(t, err)

		pidFilePath := filepath.Join(queueRes.StagingFolder, "operate-pid.json")

		var lastProgressValue float64
		printProgress := func(params *butlerd.ProgressNotification) {
			log.Printf("%.2f%% done @ %s / s ETA %s", params.Progress*100, progress.FormatBytes(int64(params.BPS)), time.Duration(params.ETA*float64(time.Second)))
			lastProgressValue = params.Progress
		}

		gracefulCancelOnce := &sync.Once{}

		messages.Progress.Register(h, func(rc *butlerd.RequestContext, params *butlerd.ProgressNotification) {
			printProgress(params)

			if params.Progress > 0.2 {
{'fraction_non_alphanumeric': 0.1410950661853189, 'fraction_numerical': 0.013838748495788207, 'mean_word_length': 4.46875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4613081', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1219, 'n_words': 204}