package topology import ( "testing" "github.com/seaweedfs/seaweedfs/weed/storage/types" ) // shiftingDataNode reports a different free slot count on each read, as a // heartbeat landing mid-selection would. type shiftingDataNode struct { *DataNode reads []int64 } func (s *shiftingDataNode) AvailableSpaceFor(*VolumeGrowOption) int64 { v := s.reads[0] if len(s.reads) > 1 { s.reads = s.reads[1:] } return v } func TestPickNodesByWeightReadsCapacityOnce(t *testing.T) { rack := NewRack("rack1") addMaintenanceTestNode(rack, "steady", 10) shifting := &shiftingDataNode{DataNode: NewDataNode("shifting"), reads: []int64{10, 10, 0}} rack.LinkChildNode(shifting) option := &VolumeGrowOption{DiskType: types.HardDriveType} first, rest, err := rack.PickNodesByWeight(2, option, func(Node) error { return nil }) if err != nil { t.Fatalf("PickNodesByWeight: %v", err) } if first == nil || len(rest) != 1 { t.Fatalf("picked first=%v and %d more nodes, want 1 more", first, len(rest)) } }