Skip to content

Commit

Permalink
Fix -= operator implementation in SuspendableThrottlerCount
Browse files Browse the repository at this point in the history
The `-=` operator overload (D1 `opSubAssign`) was inexplicably aliased
to the `add` method rather than the correct `remove`.  This probably
means that no one was ever actually using the operator overload, but it
seems a good idea to fix it in any case.
  • Loading branch information
joseph-wakeling-frequenz authored and ben-palmer-sociomantic committed Oct 15, 2019
1 parent 7bc9aa0 commit 19bd05b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
8 changes: 8 additions & 0 deletions relnotes/suspendable-throttler-count-opsubassign.bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Fix `-=` operator implementation in SuspendableThrottlerCount

`ocean.io.model.SuspendableThrottlerCount`

The `-=` operator overload (D1 `opSubAssign`) was inexplicably aliased
to the `add` method rather than the correct `remove`. This probably
means that no one was ever actually using the operator overload, but it
seems a good idea to fix it in any case.
48 changes: 47 additions & 1 deletion src/ocean/io/model/SuspendableThrottlerCount.d
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public class SuspendableThrottlerCount : ISuspendableThrottlerCount
super.throttledResume();
}

public alias add opSubAssign;
public alias remove opSubAssign;


/***************************************************************************
Expand All @@ -176,6 +176,52 @@ public class SuspendableThrottlerCount : ISuspendableThrottlerCount
}
}

unittest
{
import ocean.core.Test : test;

// Helper class to allow us to test operator overloads
// without touching other parts of the class logic
static class OpsTest : SuspendableThrottlerCount
{
this ()
{
size_t suspend_point = 8;
size_t resume_point = 3;
super(suspend_point, resume_point);
}

override void inc () { this.count++; }
override void dec () { this.count--; }

override void add (size_t n) { this.count += n; }
override void remove (size_t n) { this.count -= n; }
}

scope ops_test = new OpsTest;
test!"=="(ops_test.length, 0);

ops_test++;
test!"=="(ops_test.length, 1);
test(!ops_test.suspend);
test(ops_test.resume);

ops_test += 7;
test!"=="(ops_test.length, 8);
test(ops_test.suspend);
test(!ops_test.resume);

ops_test--;
test!"=="(ops_test.length, 7);
test(!ops_test.suspend);
test(!ops_test.resume);

ops_test -= 4;
test!"=="(ops_test.length, 3);
test(!ops_test.suspend);
test(ops_test.resume);
}


/*******************************************************************************
Expand Down

0 comments on commit 19bd05b

Please sign in to comment.