(x *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestSlotState(x *testing.T) { |
| 14 | t := openTopom() |
| 15 | defer t.Close() |
| 16 | |
| 17 | const sid = 1 |
| 18 | const gid1 = 1 |
| 19 | const gid2 = 2 |
| 20 | const server1 = "server1:port" |
| 21 | const server2 = "server2:port" |
| 22 | |
| 23 | check := func() { |
| 24 | ctx, err := t.newContext() |
| 25 | assert.MustNoError(err) |
| 26 | m, err := ctx.getSlotMapping(sid) |
| 27 | assert.MustNoError(err) |
| 28 | assert.Must(m.Id == sid) |
| 29 | assert.Must(m.GroupId == gid1 && m.Action.TargetId == gid2) |
| 30 | |
| 31 | g1, err := ctx.getGroup(gid1) |
| 32 | assert.MustNoError(err) |
| 33 | assert.Must(ctx.getGroupMaster(gid1) == server1) |
| 34 | |
| 35 | g2, err := ctx.getGroup(gid2) |
| 36 | assert.MustNoError(err) |
| 37 | assert.Must(ctx.getGroupMaster(gid2) == server2) |
| 38 | |
| 39 | slot := ctx.toSlot(m, nil) |
| 40 | |
| 41 | switch m.Action.State { |
| 42 | case models.ActionPrepared: |
| 43 | assert.Must(slot.Locked == true) |
| 44 | case models.ActionMigrating: |
| 45 | switch { |
| 46 | case g1.Promoting.State == models.ActionPrepared: |
| 47 | assert.Must(slot.Locked == true) |
| 48 | case g2.Promoting.State == models.ActionPrepared: |
| 49 | assert.Must(slot.Locked == true) |
| 50 | default: |
| 51 | assert.Must(slot.Locked == false) |
| 52 | assert.Must(slot.BackendAddr == server2) |
| 53 | assert.Must(slot.MigrateFrom == server1) |
| 54 | } |
| 55 | case models.ActionFinished: |
| 56 | switch { |
| 57 | case g2.Promoting.State == models.ActionPrepared: |
| 58 | assert.Must(slot.Locked == true) |
| 59 | default: |
| 60 | assert.Must(slot.Locked == false) |
| 61 | assert.Must(slot.BackendAddr == server2) |
| 62 | assert.Must(slot.MigrateFrom == "") |
| 63 | } |
| 64 | default: |
| 65 | switch { |
| 66 | case g1.Promoting.State == models.ActionPrepared: |
| 67 | assert.Must(slot.Locked == true) |
| 68 | default: |
| 69 | assert.Must(slot.Locked == false) |
| 70 | assert.Must(slot.BackendAddr == server1) |
nothing calls this directly
no test coverage detected