# Snowcast Autograder Test Documentation
## Control Tests
### Startup And Connecting
#### TestConnectsToServer
Checks that the control can connect to the server and send a `HELLO` message to
the server.
#### TestCompletesHandshake
Checks that the the control receives and handles the `WELCOME` reply from the
server after the control sends a `HELLO` message. This test passes if the
control is able to print out the number of stations.
#### TestMultipleWelcomesFails
Checks that the control disconnects from the server if the server sends
multiple `WELCOME` replies.
#### TestNoWelcomeFails
Checks that the control closes the connection to the server if the server
does not respond with a `WELCOME` 100ms after the control sends a `HELLO`.
### Handling Partial Messages
#### TestPartialWelcomeTimeoutFails
Checks that control terminates its connection to the server if the server
does not receive a complete `WELCOME` message.
This test waits for the control to send a `HELLO`, and then responds with
only the first few bytes a of a `WELCOME` reply. The control is expected to
to terminate its connection to server after 100ms and not receiving the
complete `WELCOME`.
#### TestSplitWelcomeSucceeds1
Checks that the control can successfully receive a `WELCOME` message from the
server that is sent across two packets.
This test waits for the control to send a `HELLO`, and then the test server
responds with the first half of the `WELCOME` message, waits some time, and
then sends the final half of the `WELCOME` message to the control.
#### TestSplitWelcomeSucceeds2
Checks that the control can successfully receive a `WELCOME` message from the
server that is sent across multiple packets.
This test waits for the control to send a `HELLO`, and then the test server
responds with packets each containing one byte of the `WELCOME` reply, with
some delay between each packet.
#### TestPartialAnnounceTimeoutFails
Checks thats the control closes its connection to the server if the control
receives part of the `ANNOUNCE` message and does not receive the remainder of
the `ANNOUNCE` message within 100ms of receiving the first part.
#### TestSplitAnnounceSucceeds1
Checks that the control can successfully receive an `ANNOUNCE` message from the
server that is sent across two packets.
The test server responds with the first half of the `ANNOUNCE` message,
waits some time, and then sends the final half of the `ANNOUNCE` message to
the control.
#### TestSplitAnnounceSucceeds2
Checks that the control can successfully receive a `ANNOUNCE` message from the
server that is sent across multiple packets.
The test server responds with packets each containing one byte of the
`ANNOUNCE` reply, with some delay between each packet.
### Message Formatting
#### TestSetStationFormat
Checks that the control sends `SET_STATION` commands in the correct format.
#### TestExitsOnInvalidCommand
Checks that the control terminates if the server sends an invalid command
message to the control.
#### TestExitsOnInvalidReplyType
Checks that the control terminates its connection with the server if the
server responds with an invalid reply type to the control (i.e some unknown
reply type).
### Miscellaneous Functionality
#### TestPrintsAnnounce1
Checks that the control can print a single `ANNOUNCE` message received from the
server.
#### TestPrintsAnnounce2
Checks that the control can continuously print a `ANNOUNCE` messages received
from the server. This test sends 10 `ANNOUNCE` messages to the control and
checks that the control can print all 10 `ANNOUNCE` messages.
#### TestAnnounceBeforeSetStationFails
Checks that the control terminates its connection with the server if the
control receives an `ANNOUNCE` message from the server before sending a
`SET_STATION` message to the server.
#### TestSetStationInvalidCommandResponseFails
Checks that the control terminates its connection to the server if the server
responds with the incorrect response type (i.e responding with a `WELCOME`
instead of an `ANNOUNCE`)
#### TestQuitsCleanly
Checks that the control can exit cleanly when the user inputs the quit
command to the control CLI.
## Server Tests
### Startup and Connecting to Clients
#### TestServerShouldFailIfNoStations
Checks that the server fails to start if no stations were provided
#### TestServerCanAcceptClientConnection
Checks that the server does not fail when accepting a single connection.
#### TestServerTerminatesClientIfNoHello
Checks that the server closes a client connection when the client does not
send a `HELLO` message within 100ms of connecting to the server.
#### TestServerDoesCompleteHandshake
Checks that the server responds with a `WELCOME` response, completing the
handshake, when the client sends a `HELLO` message.
#### TestServerTerminatesClientIfMultipleHellos
Checks that the server terminate a client connection if the client sends
multiple `HELLO` messages.
#### TestServerSurvivesClientDisconnect
Checks that the server does not fail if a client disconnects.
### Handling Partial Messages
#### TestServerTerminatesClientIfIncompleteHello
Checks that server terminates a client connection if the server does not
receive a complete `HELLO` message.
This test sends only the first few bytes of the `HELLO` message to the server
and the server is expected to terminate the client after not receiving the
full `HELLO` message with 100ms to receiving the first few bytes.
#### TestSplitHelloSucceedsTwoChunks
Checks that the server can successfully accept a `HELLO` message from the
client that is sent across multiple packets.
This test sends the first few bytes of the `HELLO` message to the server, waits
some time, and then sends the final bytes of the `HELLO` message to the server.
#### TestSplitHelloSucceedsEachByte
Checks that the server can successfully accept a `HELLO` message from the
client that is sent across multiple packets.
This test sends each byte of the `HELLO` message to the server in a separate
packet, with some delay between each of the sends.
#### TestServerTerminatesClientIfIncompleteSetStation
Checks that server terminates a client connection if the server does not
receive a complete `SET_STATION` message.
This test sends only the first few bytes of the `SET_STATION` message to the
server and the server is expected to terminate the client after not
receiving the full `SET_STATION` message with 100ms to receiving the first few
bytes.
#### TestSplitSetStationSucceedsTwoChunks
Checks that the server can successfully accept a `SET_STATION` message from the
client that is sent across multiple packets.
This test sends the first few bytes of the `SET_STATION` message to the server,
waits some time, and then sends the final bytes of the `SET_STATION` message
to the server.
#### TestSplitSetStationSucceedsEachByte
Checks that the server can successfully accept a `SET_STATION` message from
the client that is sent across multiple packets.
This test sends each byte of the `SET_STATION` message to the server in a
separate packet, with some delay between each of the sends.
### Miscellaneous Functionality
#### TestServerTerminatesClientIfSetStationBeforeHello
Checks that the server terminates a client connection if the client sends
a `SET_STATION` message before a `HELLO` message.
#### TestSetStationSucceeds
Checks that a client can successfully run a `SET_STATION` command with the
with the server.
#### TestSupportsMultipleStations
Checks that the server can support multiple stations. This test sets up the
server with multiple stations and then iterates over each file provided for a
station. For each file, the test does the following:
- send a `SET_STATION` message to the server for each station and assert that
the server responds with a corresponding `ANNOUNCE`.
- checks that the test client is placed with the correct station in the
server.
#### TestStreamsWithoutReadingEntireFile
Checks that file data is streamed a fixed number of bytes at a time instead
of reading the entire file into memory at once.
To ensure this behavior, this test uses /dev/urandom and /dev/zero as files
for the stations.
#### TestServerTerminatesClientIfInvalidSetStation
Checks that the server terminates a client connection if the client sends
a `SET_STATION` message to the server that contains an invalid station number.
#### TestAcceptsMultipleConnections
Checks that the server can handle multiple connections with each connection
have different stations.
#### TestStreamRateSingleConnectionSingleStation
Checks that the server's stream rate is 16KiB/s for a single connection
listening to one station.
#### TestStreamRateMultipleConnectionsOneStation
Checks that the server's stream rate is 16KiB/s for a multiple connections
listening to one station.
#### TestStreamRateMultipleConnectionsMultipleStations
Checks that the server's stream rate is 16KiB/s for a multiple connections
listening to different stations.
#### TestStreamsWithNoListeners
Checks that the server streams data and sends periodic `ANNOUNCE` messages
even with zero client connections.
#### TestServerTerminatesClientIfInvalidCommandType
Checks that the server terminates a client connection if the client sends a
command with an unrecognized command type.