Skip to content

Commit

Permalink
Remove unneeded message widgets (#40)
Browse files Browse the repository at this point in the history
* Remove unneeded message widgets

* Remove unused stuff
  • Loading branch information
nakabonne authored Oct 3, 2020
1 parent c2d447f commit 9bd47e0
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 64 deletions.
14 changes: 0 additions & 14 deletions gui/drawer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ type drawer struct {
chartCh chan *attacker.Result
gaugeCh chan bool
metricsCh chan *attacker.Metrics
// TODO: Remove
messageCh chan string

// aims to avoid to perform multiple `redrawChart`.
chartDrawing bool
Expand Down Expand Up @@ -160,15 +158,3 @@ func (d *drawer) redrawMetrics(ctx context.Context) {
}
}
}

func (d *drawer) redrawMessage(ctx context.Context) {
defer close(d.messageCh)
for {
select {
case <-ctx.Done():
return
case m := <-d.messageCh:
d.widgets.messageText.Write(m, text.WriteReplace())
}
}
}
35 changes: 0 additions & 35 deletions gui/drawer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,38 +265,3 @@ End: 2009-11-10 23:00:00 +0000 UTC`, gomock.Any())
})
}
}

func TestRedrawMessage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

tests := []struct {
name string
message string
text Text
}{
{
name: "write foo",
message: "foo",
text: func() Text {
g := NewMockText(ctrl)
g.EXPECT().Write("foo", gomock.Any())
return g
}(),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
d := &drawer{
widgets: &widgets{messageText: tt.text},
messageCh: make(chan string),
}
go d.redrawMessage(ctx)
d.messageCh <- tt.message
cancel()
<-d.messageCh
})
}
}
2 changes: 0 additions & 2 deletions gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ func run(t *termbox.Terminal, r runner, targetURL string, opts *attacker.Options
chartCh: make(chan *attacker.Result),
gaugeCh: make(chan bool),
metricsCh: make(chan *attacker.Metrics),
messageCh: make(chan string),
}
go d.redrawMetrics(ctx)
go d.redrawMessage(ctx)

k := keybinds(ctx, cancel, d, targetURL, *opts)

Expand Down
2 changes: 0 additions & 2 deletions gui/keybinds.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func keybinds(ctx context.Context, cancel context.CancelFunc, dr *drawer, target

func attack(ctx context.Context, d *drawer, target string, opts attacker.Options) {
if d.chartDrawing {
d.messageCh <- "Wait until the attack is over"
return
}
requestNum := opts.Rate * int(opts.Duration/time.Second)
Expand All @@ -34,6 +33,5 @@ func attack(ctx context.Context, d *drawer, target string, opts attacker.Options
go func(ctx context.Context, d *drawer, t string, o attacker.Options) {
attacker.Attack(ctx, t, d.chartCh, d.metricsCh, o) // this blocks until attack finishes
d.chartCh <- &attacker.Result{End: true}
d.messageCh <- "Attack completed"
}(ctx, d, target, opts)
}
2 changes: 0 additions & 2 deletions gui/keybinds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ func TestAttack(t *testing.T) {
d := &drawer{
widgets: &widgets{
latencyChart: nil,
messageText: nil,
latenciesText: nil,
bytesText: nil,
othersText: nil,
progressGauge: nil,
navi: nil,
},
messageCh: make(chan string, 100),
chartDrawing: tt.chartDrawing,
}
attack(ctx, d, "", attacker.Options{})
Expand Down
8 changes: 0 additions & 8 deletions gui/widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type widgets struct {
latencyChart LineChart

paramsText Text
messageText Text
latenciesText Text
bytesText Text
statusCodesText Text
Expand All @@ -49,10 +48,6 @@ func newWidgets(targetURL string, opts *attacker.Options) (*widgets, error) {
return nil, err
}

messageText, err := newText("Give the target URL and press Enter")
if err != nil {
return nil, err
}
latenciesText, err := newText("")
if err != nil {
return nil, err
Expand Down Expand Up @@ -90,7 +85,6 @@ func newWidgets(targetURL string, opts *attacker.Options) (*widgets, error) {
return &widgets{
latencyChart: latencyChart,
paramsText: paramsText,
messageText: messageText,
latenciesText: latenciesText,
bytesText: bytesText,
statusCodesText: statusCodesText,
Expand Down Expand Up @@ -124,9 +118,7 @@ func newText(s string) (Text, error) {

func newGauge() (Gauge, error) {
return gauge.New(
//gauge.Height(1),
gauge.Border(linestyle.None),
//gauge.BorderTitle("Progress"),
)
}

Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Author:
)

type cli struct {
target string
rate int
duration time.Duration
timeout time.Duration
Expand Down

0 comments on commit 9bd47e0

Please sign in to comment.