(c net.Conn)
| 500 | } |
| 501 | |
| 502 | func (s *mockMaintNotificationsDowngradeServer) handle(c net.Conn) { |
| 503 | defer c.Close() |
| 504 | r := bufio.NewReader(c) |
| 505 | for { |
| 506 | args, err := readRESPCommand(r) |
| 507 | if err != nil { |
| 508 | return |
| 509 | } |
| 510 | if len(args) == 0 { |
| 511 | continue |
| 512 | } |
| 513 | name := strings.ToUpper(args[0]) |
| 514 | full := name |
| 515 | if len(args) > 1 { |
| 516 | full = name + " " + strings.ToUpper(args[1]) |
| 517 | } |
| 518 | |
| 519 | switch { |
| 520 | case name == "HELLO": |
| 521 | s.record(full) |
| 522 | _, _ = c.Write([]byte("%1\r\n+proto\r\n:3\r\n")) |
| 523 | case full == maintNotificationsCommand: |
| 524 | if call := s.record(full); call == 1 { |
| 525 | _, _ = c.Write([]byte("+OK\r\n")) |
| 526 | } else { |
| 527 | _, _ = c.Write([]byte("-ERR unknown subcommand 'MAINT_NOTIFICATIONS'\r\n")) |
| 528 | } |
| 529 | case name == "PING": |
| 530 | s.record(full) |
| 531 | shouldBlock := false |
| 532 | s.blockFirstPing.Do(func() { |
| 533 | shouldBlock = true |
| 534 | close(s.firstPingBlocked) |
| 535 | }) |
| 536 | if shouldBlock { |
| 537 | <-s.releaseFirstPing |
| 538 | } |
| 539 | _, _ = c.Write([]byte("+PONG\r\n")) |
| 540 | default: |
| 541 | s.record(full) |
| 542 | _, _ = c.Write([]byte("+OK\r\n")) |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | func startMockMaintNotificationsDowngradeServer(t *testing.T) *mockMaintNotificationsDowngradeServer { |
| 548 | t.Helper() |
no test coverage detected