<commit_before>package fusetest

import (
	"fmt"
	"github.com/hashicorp/go-multierror"
	"io/ioutil"
	"koding/klient/remote/req"
	"os"
	"path/filepath"
	"testing"
	"time"

	. "github.com/smartystreets/goconvey/convey"
)

// Fusetest runs common file & dir operations on already mounted folder
// then checks if local mount and remote VM are synchronized using ssh.
type Fusetest struct {
	Machine string

	// The path of the local mount directory on the users system.
	MountDir string

	// The temporary directory within the Mount directory, where test operations
	// are run.
	TestDir string

	Opts req.MountFolder

	T *testing.T

	*Remote
}

func NewFusetest(machine string, opts req.MountFolder) (*Fusetest, error) {
	r, err := NewRemote(machine)
	if err != nil {
		return nil, err
	}

	return &Fusetest{
		Machine:  machine,
		MountDir: r.local,
		T:        &testing.T{},
		Remote:   r,
		Opts:     opts,
	}, nil
}

func (f *Fusetest) checkCachePath() bool {
	return f.Opts.CachePath != "" && f.Opts.PrefetchAll
}

func (f *Fusetest) RunAllTests() (testErrs error) {
	fmt.Println("Testing pre-existing mount...")
	if err := f.RunOperationTests(); err != nil {
		testErrs = multierror.Append(testErrs, err)
	}

	// Unmount so we can mount with various settings below.
	if err := NewKD().Unmount(f.Machine); err != nil {
		testErrs = multierror.Append(testErrs, err)
	}

	// Run our various test types
	if err := f.RunPrefetchTests(); err != nil {
		testErrs = multierror.Append(testErrs, err)
	}

	if err := f.RunNoPrefetchTests(); err != nil {
		testErrs = multierror.Append(testErrs, err)
	}

	if err := f.RunPrefetchAllTests(); err != nil {
		testErrs = multierror.Append(testErrs, err)
	}

	// Remount test folder.
	//
	// TODO: Perhaps store the current mount settings, so we can mount after we're
	// done with the same settings?
	err := NewKD().MountWithPrefetchAll(f.Machine, f.Remote.remote, f.MountDir)
	if err != nil {
		testErrs = multierror.Append(testErrs, err)
	}

	return testErrs
}

func (f *Fusetest) RunPrefetchTests() error {
	fmt.Println("Mounting with Prefetch...")

	// TODO: Add the fusetest dir to Fusetest.RemoteDir. I haven't yet, because
	// i want to make it the full abs path, rather than just a local path as seen here.
	err := NewKD().Mount(f.Machine, f.Remote.remote, f.MountDir)
	if err != nil {
		return err
	}

	if err := f.RunOperationTests(); err != nil {
		return err
	}

	// Pausing, because the instant remount is giving me resource is busy every
	// time.
	time.Sleep(5 * time.Second)

	return NewKD().Unmount(f.Machine)
}

func (f *Fusetest) RunNoPrefetchTests() error {
	fmt.Println("Mounting with NoPrefetch...")

	// TODO: Add the fusetest dir to Fusetest.RemoteDir. I haven't yet, because
	// i want to make it the full abs path, rather than just a local path as seen here.
	err := NewKD().Mount(f.Machine, f.Remote.remote, f.MountDir)
	if err != nil {
		return err
	}

	if err := f.RunOperationTests(); err != nil {
		return err
	}

	// Pausing, because the instant remount is giving me resource is busy every
	// time.
	time.Sleep(5 * time.Second)

	return NewKD().Unmount(f.Machine)
}

func (f *Fusetest) RunPrefetchAllTests() error {
	fmt.Println("Mounting with PrefetchAll...")

	// TODO: Add the fusetest dir to Fusetest.RemoteDir. I haven't yet, because
	// i want to make it the full abs path, rather than just a local path as seen here.
	err := NewKD().MountWithPrefetchAll(f.Machine, f.Remote.remote, f.MountDir)
	if err != nil {
		return err
	}

	if err := f.RunOperationTests(); err != nil {
		return err
	}

	// Pausing, because the instant remount is giving me resource is busy every
	// time.
	time.Sleep(5 * time.Second)

	return NewKD().Unmount(f.Machine)
}
<commit_msg>fusetest: Removed Sleep, Resource Is Busy is no longer an issue<commit_after>package fusetest

import (
	"fmt"
	"github.com/hashicorp/go-multierror"
	"io/ioutil"
	"koding/klient/remote/req"
	"os"
	"path/filepath"
	"testing"

	. "github.com/smartystreets/goconvey/convey"
)

// Fusetest runs common file & dir operations on already mounted folder
// then checks if local mount and remote VM are synchronized using ssh.
type Fusetest struct {
	Machine string

	// The path of the local mount directory on the users system.
	MountDir string

	// The temporary directory within the Mount directory, where test operations
	// are run.
	TestDir string

	Opts req.MountFolder

	T *testing.T

	*Remote
}

func NewFusetest(machine string, opts req.MountFolder) (*Fusetest, error) {
	r, err := NewRemote(machine)
	if err != nil {
		return nil, err
	}

	return &Fusetest{
		Machine:  machine,
		MountDir: r.local,
		T:        &testing.T{},
		Remote:   r,
		Opts:     opts,
	}, nil
}

func (f *Fusetest) checkCachePath() bool {
	return f.Opts.CachePath != "" && f.Opts.PrefetchAll
}

func (f *Fusetest) RunAllTests() (testErrs error) {
	fmt.Println("Testing pre-existing mount...")
	if err := f.RunOperationTests(); err != nil {
		testErrs = multierror.Append(testErrs, err)
	}

	// Unmount so we can mount with various settings below.
	if err := NewKD().Unmount(f.Machine); err != nil {
		testErrs = multierror.Append(testErrs, err)
	}

	// Run our various test types
	if err := f.RunPrefetchTests(); err != nil {
		testErrs = multierror.Append(testErrs, err)
	}

	if err := f.RunNoPrefetchTests(); err != nil {
		testErrs = multierror.Append(testErrs, err)
	}

	if err := f.RunPrefetchAllTests(); err != nil {
		testErrs = multierror.Append(testErrs, err)
	}

	// Remount test folder.
	//
	// TODO: Perhaps store the current mount settings, so we can mount after we're
	// done with the same settings?
	err := NewKD().MountWithPrefetchAll(f.Machine, f.Remote.remote, f.MountDir)
	if err != nil {
		testErrs = multierror.Append(testErrs, err)
	}

	return testErrs
}

func (f *Fusetest) RunPrefetchTests() error {
	fmt.Println("Mounting with Prefetch...")

	// TODO: Add the fusetest dir to Fusetest.RemoteDir. I haven't yet, because
	// i want to make it the full abs path, rather than just a local path as seen here.
	err := NewKD().Mount(f.Machine, f.Remote.remote, f.MountDir)
	if err != nil {
		return err
	}

	if err := f.RunOperationTests(); err != nil {
		return err
	}

	return NewKD().Unmount(f.Machine)
}

func (f *Fusetest) RunNoPrefetchTests() error {
	fmt.Println("Mounting with NoPrefetch...")

	// TODO: Add the fusetest dir to Fusetest.RemoteDir. I haven't yet, because
	// i want to make it the full abs path, rather than just a local path as seen here.
	err := NewKD().Mount(f.Machine, f.Remote.remote, f.MountDir)
	if err != nil {
		return err
	}

	if err := f.RunOperationTests(); err != nil {
		return err
	}

	return NewKD().Unmount(f.Machine)
}

func (f *Fusetest) RunPrefetchAllTests() error {
	fmt.Println("Mounting with PrefetchAll...")

	// TODO: Add the fusetest dir to Fusetest.RemoteDir. I haven't yet, because
	// i want to make it the full abs path, rather than just a local path as seen here.
	err := NewKD().MountWithPrefetchAll(f.Machine, f.Remote.remote, f.MountDir)
	if err != nil {
		return err
	}

	if err := f.RunOperationTests(); err != nil {
		return err
	}

	return NewKD().Unmount(f.Machine)
}

{'fraction_non_alphanumeric': 0.12383079715203127, 'fraction_numerical': 0.00041881893061566385, 'mean_word_length': 3.5056603773584905, 'pattern_counts': {'":': 0, '<': 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': '4313189', 'n_tokens_mistral': 2572, 'n_tokens_neox': 2487, 'n_words': 792}