swarm/storage/localstore: fix tests for windows os (#19161)
This commit is contained in:
		
							parent
							
								
									340a53a98b
								
							
						
					
					
						commit
						c83ba9e794
					
				| @ -22,6 +22,7 @@ import ( | |||||||
| 	"io/ioutil" | 	"io/ioutil" | ||||||
| 	"math/rand" | 	"math/rand" | ||||||
| 	"os" | 	"os" | ||||||
|  | 	"runtime" | ||||||
| 	"sort" | 	"sort" | ||||||
| 	"strconv" | 	"strconv" | ||||||
| 	"sync" | 	"sync" | ||||||
| @ -34,6 +35,26 @@ import ( | |||||||
| 	"github.com/syndtr/goleveldb/leveldb" | 	"github.com/syndtr/goleveldb/leveldb" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | func init() { | ||||||
|  | 	// Some of the tests in localstore package rely on the same ordering of
 | ||||||
|  | 	// items uploaded or accessed compared to the ordering of items in indexes
 | ||||||
|  | 	// that contain StoreTimestamp or AccessTimestamp in keys. In tests
 | ||||||
|  | 	// where the same order is required from the database as the order
 | ||||||
|  | 	// in which chunks are put or accessed, if the StoreTimestamp or
 | ||||||
|  | 	// AccessTimestamp are the same for two or more sequential items
 | ||||||
|  | 	// their order in database will be based on the chunk address value,
 | ||||||
|  | 	// in which case the ordering of items/chunks stored in a test slice
 | ||||||
|  | 	// will not be the same. To ensure the same ordering in database on such
 | ||||||
|  | 	// indexes on windows systems, an additional short sleep is added to
 | ||||||
|  | 	// the now function.
 | ||||||
|  | 	if runtime.GOOS == "windows" { | ||||||
|  | 		setNow(func() int64 { | ||||||
|  | 			time.Sleep(time.Microsecond) | ||||||
|  | 			return time.Now().UTC().UnixNano() | ||||||
|  | 		}) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // TestDB validates if the chunk can be uploaded and
 | // TestDB validates if the chunk can be uploaded and
 | ||||||
| // correctly retrieved.
 | // correctly retrieved.
 | ||||||
| func TestDB(t *testing.T) { | func TestDB(t *testing.T) { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user