This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Categorize session restoration errors
Dedicate special reply message types for "session not found" and "session reached max connections" errors. Add test to verify the correct error type is returned during restoration of an inexistent session.
- Loading branch information
Showing
8 changed files
with
110 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
wwr "github.com/qbeon/webwire-go" | ||
wwrClient "github.com/qbeon/webwire-go/client" | ||
) | ||
|
||
// TestRestoreInexistentSession tests the restoration of an inexistent session | ||
func TestRestoreInexistentSession(t *testing.T) { | ||
// Initialize server | ||
_, addr := setupServer( | ||
t, | ||
wwr.ServerOptions{ | ||
Hooks: wwr.Hooks{ | ||
// Permanently store the session | ||
OnSessionCreated: func(_ *wwr.Client) error { | ||
return nil | ||
}, | ||
// Find session by key | ||
OnSessionLookup: func(_ string) (*wwr.Session, error) { | ||
return nil, nil | ||
}, | ||
// Define dummy hook to enable sessions on this server | ||
OnSessionClosed: func(_ *wwr.Client) error { | ||
return nil | ||
}, | ||
}, | ||
}, | ||
) | ||
|
||
// Initialize client | ||
|
||
// Ensure that the last superfluous client is rejected | ||
client := wwrClient.NewClient( | ||
addr, | ||
wwrClient.Options{ | ||
DefaultRequestTimeout: 2 * time.Second, | ||
}, | ||
) | ||
|
||
if err := client.Connect(); err != nil { | ||
t.Fatalf("Couldn't connect client: %s", err) | ||
} | ||
|
||
// Try to restore the session and expect it to fail due to the session being inexistent | ||
sessRestErr := client.RestoreSession([]byte("lalala")) | ||
if _, isSessNotFoundErr := sessRestErr.(wwr.SessNotFound); !isSessNotFoundErr { | ||
t.Fatalf( | ||
"Expected a SessNotFound error during manual session restoration, got: %s | %s", | ||
reflect.TypeOf(sessRestErr), | ||
sessRestErr, | ||
) | ||
} | ||
} |