Beispiel #1
0
func (s *managedStorageSuite) TestPutRequestSingle(c *gc.C) {
	ch := make(chan struct{})
	s.PatchValue(storage.AfterFunc, patchedAfterFunc(ch))
	s.assertPutRequestSingle(c, nil, 1)
	c.Assert(storage.RequestQueueLength(s.managedStorage), gc.Equals, 0)
	// Trigger the request timeout.
	ch <- trigger
	<-ch
	c.Assert(storage.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}
Beispiel #2
0
// Run one simple test with the real time.AfterFunc to ensure it works.
func (s *managedStorageSuite) TestPutRequestExpiredWithRealTimeAfter(c *gc.C) {
	s.PatchValue(storage.RequestExpiry, 5*time.Millisecond)
	blob, md5hash, sha256hash := s.putTestBlob(c, "path/to/blob")
	hash := storage.ResourceHash{md5hash, sha256hash}
	reqResp, err := s.managedStorage.PutForEnvironmentRequest("env", "path/to/blob", hash)
	c.Assert(err, gc.IsNil)
	md5Response, sha256Response := calculateCheckSums(c, reqResp.RangeStart, reqResp.RangeLength, blob)
	// Wait for request timer to trigger.
	time.Sleep(7 * time.Millisecond)
	response := storage.NewPutResponse(reqResp.RequestId, md5Response, sha256Response)
	err = s.managedStorage.ProofOfAccessResponse(response)
	c.Assert(err, gc.Equals, storage.ErrRequestExpired)
	c.Assert(storage.RequestQueueLength(s.managedStorage), gc.Equals, 0)
	c.Assert(storage.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}
Beispiel #3
0
func (s *managedStorageSuite) TestPutRequestLarge(c *gc.C) {
	ch := make(chan struct{})
	s.PatchValue(storage.AfterFunc, patchedAfterFunc(ch))
	// Use a blob size of 4096 which is greater than max range of put response range length.
	blob := make([]byte, 4096)
	for i := 0; i < 4096; i++ {
		blob[i] = byte(rand.Intn(255))
	}
	s.assertPutRequestSingle(c, blob, 1)
	c.Assert(storage.RequestQueueLength(s.managedStorage), gc.Equals, 0)
	// Trigger the request timeout.
	ch <- trigger
	<-ch
	c.Assert(storage.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}
Beispiel #4
0
func (s *managedStorageSuite) TestPutRequestMultiRandom(c *gc.C) {
	ch := make(chan struct{})
	s.PatchValue(storage.AfterFunc, patchedAfterFunc(ch))
	done := make(chan struct{})
	s.queuePutRequests(c, done)
	select {
	case <-done:
		c.Logf("all done")
	case <-time.After(testing.LongWait):
		c.Fatalf("timed out waiting for put requests to be processed")
	}
	// One request hasn't been processed since we left it to timeout.
	c.Assert(storage.RequestQueueLength(s.managedStorage), gc.Equals, 1)
	// Trigger the request timeout.
	ch <- trigger
	<-ch
	c.Assert(storage.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}
Beispiel #5
0
func (s *managedStorageSuite) TestPutRequestResponseSHA256Mismatch(c *gc.C) {
	blob, md5hash, sha256hash := s.putTestBlob(c, "path/to/blob")
	hash := storage.ResourceHash{md5hash, sha256hash}
	reqResp, err := s.managedStorage.PutForEnvironmentRequest("env", "path/to/blob", hash)
	c.Assert(err, gc.IsNil)
	md5Response, _ := calculateCheckSums(c, reqResp.RangeStart, reqResp.RangeLength, blob)
	response := storage.NewPutResponse(reqResp.RequestId, md5Response, "notsha256")
	err = s.managedStorage.ProofOfAccessResponse(response)
	c.Assert(err, gc.Equals, storage.ErrResponseMismatch)
	c.Assert(storage.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}
Beispiel #6
0
func (s *managedStorageSuite) TestPutRequestExpired(c *gc.C) {
	ch := make(chan struct{})
	s.PatchValue(storage.AfterFunc, patchedAfterFunc(ch))
	blob, md5hash, sha256hash := s.putTestBlob(c, "path/to/blob")
	hash := storage.ResourceHash{md5hash, sha256hash}
	reqResp, err := s.managedStorage.PutForEnvironmentRequest("env", "path/to/blob", hash)
	c.Assert(err, gc.IsNil)
	md5Response, sha256Response := calculateCheckSums(c, reqResp.RangeStart, reqResp.RangeLength, blob)
	// Trigger the request timeout.
	ch <- trigger
	<-ch
	response := storage.NewPutResponse(reqResp.RequestId, md5Response, sha256Response)
	err = s.managedStorage.ProofOfAccessResponse(response)
	c.Assert(err, gc.Equals, storage.ErrRequestExpired)
	c.Assert(storage.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}