@ -15,7 +15,6 @@ import (
)
)
func TestResume ( t * testing . T ) {
func TestResume ( t * testing . T ) {
t . Skip ( "currently failing on Windows" )
oldBlockSize := blockSize
oldBlockSize := blockSize
defer func ( ) { blockSize = oldBlockSize } ( )
defer func ( ) { blockSize = oldBlockSize } ( )
blockSize = 256
blockSize = 256
@ -29,11 +28,14 @@ func TestResume(t *testing.T) {
t . Run ( "resume-noexist" , func ( t * testing . T ) {
t . Run ( "resume-noexist" , func ( t * testing . T ) {
r := io . Reader ( bytes . NewReader ( want ) )
r := io . Reader ( bytes . NewReader ( want ) )
next , close , err := m . HashPartialFile ( "" , "foo" )
next , close , err := m . HashPartialFile ( "" , "foo" )
must . Do ( err )
must . Do ( err )
defer close ( )
defer close ( )
offset , r , err := ResumeReader ( r , next )
offset , r , err := ResumeReader ( r , next )
must . Do ( err )
must . Do ( err )
must . Do ( close ( ) ) // Windows wants the file handle to be closed to rename it.
must . Get ( m . PutFile ( "" , "foo" , r , offset , - 1 ) )
must . Get ( m . PutFile ( "" , "foo" , r , offset , - 1 ) )
got := must . Get ( os . ReadFile ( must . Get ( joinDir ( m . opts . Dir , "foo" ) ) ) )
got := must . Get ( os . ReadFile ( must . Get ( joinDir ( m . opts . Dir , "foo" ) ) ) )
if ! bytes . Equal ( got , want ) {
if ! bytes . Equal ( got , want ) {
@ -43,25 +45,30 @@ func TestResume(t *testing.T) {
t . Run ( "resume-retry" , func ( t * testing . T ) {
t . Run ( "resume-retry" , func ( t * testing . T ) {
rn := rand . New ( rand . NewSource ( 0 ) )
rn := rand . New ( rand . NewSource ( 0 ) )
for {
for i := 0 ; true ; i ++ {
r := io . Reader ( bytes . NewReader ( want ) )
r := io . Reader ( bytes . NewReader ( want ) )
next , close , err := m . HashPartialFile ( "" , "foo" )
next , close , err := m . HashPartialFile ( "" , "bar" )
must . Do ( err )
must . Do ( err )
defer close ( )
defer close ( )
offset , r , err := ResumeReader ( r , next )
offset , r , err := ResumeReader ( r , next )
must . Do ( err )
must . Do ( err )
must . Do ( close ( ) ) // Windows wants the file handle to be closed to rename it.
numWant := rn . Int63n ( min ( int64 ( len ( want ) ) - offset , 1000 ) + 1 )
numWant := rn . Int63n ( min ( int64 ( len ( want ) ) - offset , 1000 ) + 1 )
if offset < int64 ( len ( want ) ) {
if offset < int64 ( len ( want ) ) {
r = io . MultiReader ( io . LimitReader ( r , numWant ) , iotest . ErrReader ( io . ErrClosedPipe ) )
r = io . MultiReader ( io . LimitReader ( r , numWant ) , iotest . ErrReader ( io . ErrClosedPipe ) )
}
}
if _ , err := m . PutFile ( "" , " foo ", r , offset , - 1 ) ; err == nil {
if _ , err := m . PutFile ( "" , " bar ", r , offset , - 1 ) ; err == nil {
break
break
}
}
if i > 1000 {
t . Fatalf ( "too many iterations to complete the test" )
}
}
}
got := must . Get ( os . ReadFile ( must . Get ( joinDir ( m . opts . Dir , "foo" ) ) ) )
got := must . Get ( os . ReadFile ( must . Get ( joinDir ( m . opts . Dir , " bar ") ) ) )
if ! bytes . Equal ( got , want ) {
if ! bytes . Equal ( got , want ) {
t . Errorf ( "content mismatches" )
t . Errorf ( "content mismatches" )
}
}
} )
} )
}
}