Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Fix capacity op and improve its test
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Dec 20, 2021
1 parent c4b164d commit e9d0a42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
23 changes: 17 additions & 6 deletions docks/op_capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func runCapacityTestOp(t terminal.OpTerminal, opID uint32, data *container.Conta
return nil, terminal.ErrMalformedData.With("failed to parse options: %w", err)
}

// Check options.
if opts.TestVolume > maxCapacityTestVolume {
return nil, terminal.ErrInvalidOptions.With("maximum volume exceeded")
}

// Create operation.
op := &CapacityTestOp{
t: t,
Expand Down Expand Up @@ -134,7 +139,7 @@ func (op *CapacityTestOp) countSentData(amount int) (done bool) {
op.measureLock.Lock()
defer op.measureLock.Unlock()

op.dataSent += len(capacityTestSendData)
op.dataSent += amount
if op.dataSent >= op.opts.TestVolume {
return true
}
Expand Down Expand Up @@ -175,22 +180,28 @@ func (op *CapacityTestOp) Deliver(c *container.Container) *terminal.Error {
op.t.OpEnd(op, tErr.Wrap("failed to send data received signal"))
return nil
}
op.dataSent += len(capacityTestDataReceivedSignal)
op.dataReceivedAckSent = true
return nil

// Flush last message.
op.t.Flush()
}

// Check if we can complete the test.
if op.dataReceived >= op.opts.TestVolume &&
op.dataReceivedAckSent &&
op.dataSent >= op.opts.TestVolume &&
op.dataSentAck {
op.dataSentAck &&
op.testResult == 0 {

// Calculate lane capacity and set it.
timeNeeded := int(time.Since(op.startTime) / time.Second)
timeNeeded := time.Since(op.startTime)
if timeNeeded <= 0 {
timeNeeded = 1
}
duplexBitRate := ((op.dataReceived + op.dataSent) * 8) / timeNeeded
op.testResult = duplexBitRate / 2
duplexNSBitRate := float64((op.dataReceived+op.dataSent)*8) / float64(timeNeeded)
bitRate := (duplexNSBitRate / 2) * float64(time.Second)
op.testResult = int(bitRate)

// Save the result to the crane.
if controller, ok := op.t.(*CraneControllerTerminal); ok {
Expand Down
3 changes: 2 additions & 1 deletion docks/op_capacity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func TestCapacityOp(t *testing.T) {
if float64(op.testResult) > expectedBitsPerSecond*1.1 {
t.Fatal("measured capacity too high")
}
if float64(op.testResult) < expectedBitsPerSecond*0.8 {
// TODO: Check if we can raise this to at least 90%.
if float64(op.testResult) < expectedBitsPerSecond*0.5 {
t.Fatal("measured capacity too low")
}
}

0 comments on commit e9d0a42

Please sign in to comment.