| 49 | } |
| 50 | |
| 51 | func TestProposal(t *testing.T) { |
| 52 | dir := t.TempDir() |
| 53 | store := raftwal.Init(dir) |
| 54 | |
| 55 | rc := &pb.RaftContext{Id: 1} |
| 56 | n := NewNode(rc, store, nil) |
| 57 | |
| 58 | peers := []raft.Peer{{ID: n.Id}} |
| 59 | n.SetRaft(raft.StartNode(n.Cfg, peers)) |
| 60 | |
| 61 | loop := 5 |
| 62 | var wg sync.WaitGroup |
| 63 | wg.Add(loop) |
| 64 | go n.run(&wg) |
| 65 | |
| 66 | for i := range loop { |
| 67 | data := []byte(fmt.Sprintf("hey-%d", i)) |
| 68 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 69 | defer cancel() |
| 70 | require.NoError(t, n.Raft().Propose(ctx, data)) |
| 71 | } |
| 72 | wg.Wait() |
| 73 | } |